mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-11-05 17:12:41 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
428ddfb78d | ||
|
|
56bd8be247 | ||
|
|
f7b2aa281e | ||
|
|
0599d504af | ||
|
|
471e0b100f | ||
|
|
52d842b27a | ||
|
|
dfc6ba91eb | ||
|
|
54d59d7b03 | ||
|
|
a4931199af | ||
|
|
02469e977c | ||
|
|
f9386fd3f1 | ||
|
|
242590f3e8 | ||
|
|
65c383491e | ||
|
|
0356c2f606 | ||
|
|
60067f75d3 | ||
|
|
e896ccb72d | ||
|
|
6c3dc58cd6 | ||
|
|
57ada83bfe | ||
|
|
8a86f05133 | ||
|
|
f447cf69d3 | ||
|
|
d06b723adc | ||
|
|
f8617cf1b9 | ||
|
|
8630a6f74c | ||
|
|
424d892091 | ||
|
|
9aaef6e297 | ||
|
|
e749760136 | ||
|
|
7f2f3c54ba | ||
|
|
24f2c867c6 | ||
|
|
e7f3288fb7 | ||
|
|
2221062e98 | ||
|
|
430f5ee9e6 | ||
|
|
cd1a7cf312 | ||
|
|
002cdc64ef | ||
|
|
3d59686ba4 | ||
|
|
f6c72b9d0e | ||
|
|
d72d419044 | ||
|
|
c71a3a4002 | ||
|
|
02b70ed324 | ||
|
|
01d0a53049 | ||
|
|
c700ca6abb | ||
|
|
d9cba6c010 | ||
|
|
a6ed66cf1e | ||
|
|
4f5b7ad3fb | ||
|
|
962ea8b719 | ||
|
|
35e4d0b5aa | ||
|
|
497fe5ef98 | ||
|
|
0508387db1 | ||
|
|
1ff7c419ef | ||
|
|
612eda685c | ||
|
|
7fc7b571a3 | ||
|
|
5cce86bf8d | ||
|
|
7621d815ac | ||
|
|
81495e3478 | ||
|
|
5c591d3a5b | ||
|
|
f1c225b718 | ||
|
|
ca7a098cfa | ||
|
|
b2fbba8455 | ||
|
|
ae6300c43c | ||
|
|
cb62734da5 | ||
|
|
04a2e4ea54 | ||
|
|
2969469605 | ||
|
|
25a0f7a742 | ||
|
|
d2f6c3336e | ||
|
|
d2c7e00639 | ||
|
|
e23fb19c98 | ||
|
|
1f8d5b78a7 | ||
|
|
fee0362c69 | ||
|
|
428d944933 | ||
|
|
180d23fb1a | ||
|
|
f54dc0f028 | ||
|
|
ef141a6e7f | ||
|
|
55b0b5df75 | ||
|
|
bc78304e97 | ||
|
|
42d8ea3526 | ||
|
|
dfc0066c17 | ||
|
|
9e3e61e9a2 | ||
|
|
6551bffcdb | ||
|
|
44f3b4d6d5 | ||
|
|
c672eaaf81 | ||
|
|
460013d22a | ||
|
|
af89f082aa | ||
|
|
e0c3c8a343 | ||
|
|
83480db4c6 | ||
|
|
04d441cfd6 | ||
|
|
842c2654c6 | ||
|
|
01d825da86 | ||
|
|
d61dd872eb | ||
|
|
3c417c6a8e | ||
|
|
f0772a0969 | ||
|
|
2a83c1c548 | ||
|
|
12114c63bf | ||
|
|
8123ff2f27 | ||
|
|
b56ebb3fcb | ||
|
|
7adcce2361 | ||
|
|
6444ec153c | ||
|
|
841253708d | ||
|
|
467308be62 | ||
|
|
d2f8305727 | ||
|
|
1a19435b96 | ||
|
|
eb4b2b1e17 | ||
|
|
8bca4bc091 | ||
|
|
dfef20fb87 | ||
|
|
f4e1dbf385 | ||
|
|
93a84f668a | ||
|
|
f8463c9927 | ||
|
|
34b5cd89e5 | ||
|
|
6aae96ab87 | ||
|
|
3f9978e3c1 | ||
|
|
f43d32ca41 | ||
|
|
f6c5777865 | ||
|
|
cdd79b76a5 | ||
|
|
5fa152f118 | ||
|
|
7a233e6e3d | ||
|
|
0697a7e903 | ||
|
|
5abf3603cf | ||
|
|
1576d4a5a6 | ||
|
|
78579f33dc | ||
|
|
3d94eac961 | ||
|
|
c31ac308f6 | ||
|
|
e201591d14 | ||
|
|
e86a8b29ae | ||
|
|
9992885f03 | ||
|
|
44ae1e58bf | ||
|
|
5550853c7d | ||
|
|
1c70555d1c | ||
|
|
9dcc11c9f4 | ||
|
|
8d942d0f2e | ||
|
|
d556290a19 | ||
|
|
bf91c80e07 | ||
|
|
d5d8a43cb5 | ||
|
|
31cc490a55 | ||
|
|
3c0f870c22 | ||
|
|
4271d31d24 | ||
|
|
0f35426dbc | ||
|
|
c19276134d | ||
|
|
a93ab63e33 | ||
|
|
e41ab428b7 | ||
|
|
a3efda4b5c | ||
|
|
e7357b1b9c | ||
|
|
d9c8485358 | ||
|
|
84b7899b29 | ||
|
|
85e6de958c | ||
|
|
9658e9dfe4 | ||
|
|
d0efa0cb26 | ||
|
|
558d0cc7fc | ||
|
|
96558955aa | ||
|
|
383e7db013 | ||
|
|
bdd53e6003 | ||
|
|
04d48403bc | ||
|
|
bb0bd8fb84 | ||
|
|
27d63ad1c5 | ||
|
|
26581fb288 | ||
|
|
db6e106eb9 | ||
|
|
fce4a52abe | ||
|
|
81d6200c51 | ||
|
|
e9b6c45113 | ||
|
|
ae1120f311 | ||
|
|
71bf486cc6 | ||
|
|
7f8e0e90d5 | ||
|
|
bc702d76ca | ||
|
|
ea0d6e4544 | ||
|
|
2838486184 | ||
|
|
6d5c127571 | ||
|
|
7bc32a196d | ||
|
|
c8ccd8f2b4 | ||
|
|
a84d932050 | ||
|
|
57774c4122 | ||
|
|
b6bade9452 | ||
|
|
be8c5e6f76 | ||
|
|
d95af1e597 | ||
|
|
589a8c320e | ||
|
|
6d23722b69 | ||
|
|
b9d0865c26 | ||
|
|
87b440c8d7 | ||
|
|
726f19de2a | ||
|
|
406b3900cd | ||
|
|
3ce05f794a | ||
|
|
06752076ff | ||
|
|
19d1ebb773 | ||
|
|
e66f5f47f3 | ||
|
|
2c56e80f57 | ||
|
|
5cb6bed49d | ||
|
|
7cc95e2060 | ||
|
|
1873997348 | ||
|
|
559e84765b | ||
|
|
6df476096d | ||
|
|
7c064e70fd | ||
|
|
55e6058b70 | ||
|
|
8a03a4faec | ||
|
|
30eb102bbc | ||
|
|
09ce792bd2 | ||
|
|
0fc23712e4 | ||
|
|
6b9c717ec4 | ||
|
|
0c3e82c01e | ||
|
|
8e6e544b60 | ||
|
|
a4196fc118 | ||
|
|
d5a9b99a7a | ||
|
|
6d850f9f07 | ||
|
|
c4987b7c5e | ||
|
|
3880738ed9 | ||
|
|
68c00b843b | ||
|
|
dc352275b6 | ||
|
|
b3362987e5 | ||
|
|
fb3ec45059 | ||
|
|
5100b4a852 | ||
|
|
e9ec801dc5 | ||
|
|
70c31b8597 | ||
|
|
a078de1fc3 | ||
|
|
a1d759451c | ||
|
|
8a9373963c | ||
|
|
d964d5b859 | ||
|
|
b468865041 | ||
|
|
d6fec721ad | ||
|
|
9256398fa2 | ||
|
|
4fed08a8f9 | ||
|
|
b650156e57 | ||
|
|
4737d15be5 | ||
|
|
aca6dd7e1d | ||
|
|
5aa0d000dd | ||
|
|
e2b238fb81 | ||
|
|
ebdb3edbc1 | ||
|
|
b9f4e46d65 | ||
|
|
287ebd4e9c | ||
|
|
befdc3de6a | ||
|
|
55d00876a7 | ||
|
|
be0ee15448 |
No files matched your search
@@ -1,21 +1,339 @@
|
||||
MIT License
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (c) 2025 Alihan
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
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
|
||||
this service 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 make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. 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.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the 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 a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE 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.
|
||||
|
||||
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
|
||||
convey 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 2 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, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision 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, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This 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.
|
||||
@@ -1,8 +1,564 @@
|
||||
# ProAntiTab
|
||||
# **A**BOUT
|
||||
ProAntiTab is an advanced **plugin hider** with **many features** and a very simple to understand system. It prevents your server from **plugin spoofers** used by hack clients, manipulates the **tab-completion**, blocks unwanted **suggestions** and much more!
|
||||
#####
|
||||
|
||||
### About
|
||||
ProAntiTab is a Spigot/Bungeecord Minecraft plugin that helps you to hide unwanted commands from your players.
|
||||
# **I**N ACTION
|
||||

|
||||
|
||||
### Support versions
|
||||
Spigot (+ Forks): 1.8x - 1.20x (latest)
|
||||
Bungeecord (+ Forks) | Waterfall recommended
|
||||
######
|
||||
# **C**USTOM SERVER BRAND (F3)
|
||||
Create your own animated custom server brand on your Spigot, Bungeecord and Velocity server!
|
||||
**
|
||||
<details>
|
||||
<summary>open config.yml section</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
# This feature allows you to customize your server-brand you see when you press F3.
|
||||
# Normally there stands something like 'Purpur', or 'Spigot'.
|
||||
# With this feature you are able to change and even animate it! ^^
|
||||
custom-server-brand:
|
||||
enabled: false
|
||||
|
||||
# Determines the speed in that the animation goes
|
||||
repeat-delay: 3
|
||||
|
||||
# This here is the list of the animation
|
||||
# Possible placeholders:
|
||||
# %player% - name of the player
|
||||
# %displayname% - displayname of the player
|
||||
# %world% - name of world where the player is
|
||||
# and the other placeholders from PlaceholderAPI
|
||||
brands:
|
||||
- '&f&lP&froAntiTab |'
|
||||
- '&fP&lr&foAntiTab /'
|
||||
- '&fPr&lo&fAntiTab -'
|
||||
- '&fPro&lA&fntiTab |'
|
||||
- '&fProA&ln&ftiTab \'
|
||||
- '&fProAn<&fiTab |'
|
||||
- '&fProAnt&li&fTab /'
|
||||
- '&fProAnti&lT&fab -'
|
||||
- '&fProAnti&lT&fab \'
|
||||
- '&fProAntiT&la&fb |'
|
||||
- '&fProAntiTa&lb&f /'
|
||||
- '&fProAntiTab -'
|
||||
- '&fProAntiTab \'
|
||||
```
|
||||
</details>
|
||||
|
||||
######
|
||||
# **U**SE BLACKLIST AS WHITELIST
|
||||
You have way too many commands to block? Don't worry.
|
||||
There's a section in the config.yml located pretty much high that allows you to turn the blacklist into a whitelist instead. This will block every command on your server except for those that are listed.
|
||||
<details>
|
||||
<summary>section in config.yml</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
# This is a very necessary feature if you have way too many commands to block and instead decide
|
||||
# to whitelist specific commands.
|
||||
# Enabling this will disable ALL commands except for those that are in the (group-)list.
|
||||
turn-blacklist-to-whitelist: false
|
||||
```
|
||||
</details>
|
||||
|
||||
######
|
||||
# **A**NTI PLUGIN SPOOFING
|
||||
##### ProAntiTab is able to detect and block plugin spoofing attempts used by hack clients.
|
||||
**
|
||||
|
||||
######
|
||||
# **B**LOCK SUB ARGUMENTS
|
||||
We all know the problem when players should be able to use some of the commands but should not see literally EVERY sub-argument in a command. Well, then just blend them out? ProAntiTab can do this for you and it's very easy to setup as well! (See some examples below)
|
||||
|
||||

|
||||
<details>
|
||||
<summary>example</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
# Let's say you just want to allow "/help Minecraft" only and not "/help apple".
|
||||
# It will also automatically allow everything after "/help Minecraft ..."
|
||||
- help Minecraft
|
||||
|
||||
# [CMD] = Allow the execution of the command
|
||||
# [TAB] = Allow the tab-completion of the command
|
||||
- "[CMD]cmi tpa" # Only executable. Not tab-completable
|
||||
- tpa # Executable & Tab-Completable
|
||||
|
||||
# %hidden_online_players% = Online players (Removed from tab-completion)
|
||||
# %online_players% = Online players
|
||||
# %hidden_players% = Registered players (Removed from tab-completion)
|
||||
# %players% = Registered players
|
||||
# %numbers% = Numbers, such as 1000 or 1.000
|
||||
# _- = Block everything after
|
||||
- "tpa %online_players%"
|
||||
- "sell %numbers%"
|
||||
|
||||
# Using the operator _- at the end cancels every argument afterwards and blocks it.
|
||||
# This will allow the player to use "/help Minecraft" but not "/help Minecraft xyz"
|
||||
- help Minecraft _-
|
||||
```
|
||||
</details>
|
||||
|
||||
######
|
||||
# **B**LOCK COLLON COMMANDS
|
||||
It's annyoing after some time to block all commands including collons like essentials:spawn. With this option you can disable them entirely for good! Only people with the proantitab.namespace permission can see these commands again.
|
||||
|
||||

|
||||
<details>
|
||||
<summary>open config.yml section</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
#>> HTP (Overwritten)
|
||||
# Here you can disable all namespace commands.
|
||||
# Namespace commands are commands like plugin:command (e.g: essentials:warp)
|
||||
# You can bypass this restriction with the proantitab.namespace permission.
|
||||
block-namespace-commands:
|
||||
enabled: false
|
||||
```
|
||||
</details>
|
||||
|
||||
######
|
||||
# **C**USTOM PLUGINS LIST
|
||||
Just blocking the /plugins command is pretty boring. This feature here allows you to make it more interesting by displaying for example fake plugins.
|
||||
|
||||

|
||||
<details>
|
||||
<summary>open config.yml section</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
#>> HTP (Overwritten)
|
||||
# Here you can customize your own fake '/plugins' command.
|
||||
custom-plugins:
|
||||
enabled: true
|
||||
commands:
|
||||
- pl
|
||||
- plugins
|
||||
- bukkit:pl
|
||||
- bukkit:plugins
|
||||
message:
|
||||
- '&fPlugins (0):'
|
||||
```
|
||||
</details>
|
||||
|
||||
######
|
||||
# **C**USTOM VERSION COMMAND
|
||||
Who wouldn't like to pretend to own a custom server-jar? Have fun customizing your very own /version command to your personal liking.
|
||||
|
||||

|
||||
<details>
|
||||
<summary>open config.yml section</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
#>> HTP (Overwritten)
|
||||
# Here you can customize your own fake '/version' command.
|
||||
custom-version:
|
||||
enabled: true
|
||||
commands:
|
||||
- version
|
||||
- ver
|
||||
- icanhasbukkit
|
||||
- bukkit:ver
|
||||
- bukkit:version
|
||||
message:
|
||||
- '&fThis server is running CraftBukkit version git-NasaSpigot-294 (MC: X)'
|
||||
```
|
||||
</details>
|
||||
|
||||
######
|
||||
# **C**USTOM UNKNOWN COMMAND MESSAGE
|
||||
The Bukkit/Spigot version of ProAntiTab gives your the possibility to create your own unknown-command message to align it with the blocked-command message for example.
|
||||
|
||||

|
||||
<details>
|
||||
<summary>open config.yml section</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
# Now there we come to the good stuff! ^^
|
||||
# If ProAntiTab is loaded on a Spigot server, you will see this option right here.
|
||||
# With that you can also customize your own "Unknown Command"-message.
|
||||
custom-unknown-command:
|
||||
enabled: true
|
||||
message:
|
||||
- '&cThis command does not exist!'
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
######
|
||||
# **C**USTOM PROTOCOL PING
|
||||
Do you know the red text message at the players count when you ping a server with the wrong version? Exactly this holds the information of what kind of server your proxy server is running at. This feature hides the version of the proxy with a custom made one. It's enabled by default but doesn't show the text. The text can be seen when someone pings the server with the wrong version or uses a resolver. This picture shows you what someone with the wrong version would see, unless the "always-show" is enabled. If this option is enabled, this text will always appear.
|
||||
|
||||
 <details>
|
||||
<summary>open config.yml section</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
# Change the protocol for the version name when the server is being pinged
|
||||
# (!) Warning: It's required to use Paper or Purpur to use this feature!
|
||||
# (!) Supported server versions: 1.12.2 - latest
|
||||
custom-protocol-ping:
|
||||
enabled: false
|
||||
|
||||
# Normally it would only display when someone pings the server with the wrong version.
|
||||
# Enabling this will always display the protocol and replace it with the normal player count.
|
||||
always-show: false
|
||||
|
||||
# This number here determines the outcome for the %online_extended% placeholder.
|
||||
# It's the current amount of players increased by this number.
|
||||
# For example: 5/20 becomes 6/20
|
||||
extend-online-count: 1
|
||||
# true: Use new calculated online-count (%online_extended%) as max-players count.
|
||||
# false: Use the default max-players count.
|
||||
use-as-maxplayers: false
|
||||
|
||||
# Enabling this option hides the list of players on your server,
|
||||
# when you hover over the player count.
|
||||
hide-players: true
|
||||
|
||||
# The displayed protocol message
|
||||
# Available placeholders:
|
||||
# %online% - current online player count
|
||||
# %online_extended% - manipulated online player count
|
||||
# %max% - max player count
|
||||
protocol: '&f&lProAntiTab &7(&a%online%&7/&c%max%&7)'
|
||||
```
|
||||
</details>
|
||||
|
||||
######
|
||||
# **C**USTOM RESPONSE ACTIONS
|
||||
For some, it's important to determine how the response message should be or what should happen. You can customize that factor to your personal liking and use different actions to have full control over your blocked commands.
|
||||
|
||||

|
||||
|
||||

|
||||
<details>
|
||||
<summary>Bukkit/Spigot examples</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
# ____ ___ __ _ ______ __
|
||||
# / __ \_________ / | ____ / /_(_)_ __/___ _/ /_
|
||||
# / /_/ / ___/ __ \/ /| | / __ \/ __/ / / / / __ `/ __ \
|
||||
# / ____/ / / /_/ / ___ |/ / / / /_/ / / / / /_/ / /_/ /
|
||||
# /_/ /_/ \____/_/ |_/_/ /_/\__/_/ /_/ \__,_/_.___/
|
||||
# custom-responses.yml
|
||||
#
|
||||
# Here you can configure a few of the blocked commands a bit further.
|
||||
# But what exactly is this here? Every command that would normally respond with the typical "command is blocked" message, can be configured in here!
|
||||
# And how does it work? It's simple. You just provide the a trigger of the command that would be normally blocked.
|
||||
# Commands that would normally work won't send the messages you have set here.
|
||||
# This way PAT can offer you full control over certain commands and their normal responses.
|
||||
# What are these action section at each block?
|
||||
# This is an additional feature to make your responses much more alive.
|
||||
# Example actions that can be used are the following:
|
||||
# Execute console command:
|
||||
# Syntax: console::command
|
||||
# Example: console::say %player% is an evil player
|
||||
# Execute player command:
|
||||
# Syntax: execute::command
|
||||
# Example: execute::help
|
||||
# Send actionbar:
|
||||
# Syntax: actionbar::text
|
||||
# Example: actionbar::&cThis is not cool %player%!
|
||||
# Send title:
|
||||
# Syntax: title::title::subtitle::5::20::5
|
||||
# Example: title::&aTest title::&cHello %player%!
|
||||
# Play sound:
|
||||
# Syntax: sound::soundName::volume::pitch
|
||||
# Example: sound::ENTITY_ENDER_DRAGON_GROWL::1.0::1.0
|
||||
# Give potion effect:
|
||||
# Syntax: effect::potionEffect::duration::amplifier
|
||||
# Example: effect::BLINDNESS::45::1
|
||||
|
||||
# Here are a few examples:
|
||||
|
||||
# Example with kits.
|
||||
# In here we only trigger the given message, if the player would type "/kit ...".
|
||||
# If this command would work through sub-arguments, then the player would only able to execute the command with the
|
||||
# listed sub-arguments assigned to it. Everything else will result with the set message in there.
|
||||
# --
|
||||
#example-with-kits:
|
||||
# triggers:
|
||||
# - "kit *"
|
||||
# message:
|
||||
# - "&cThis kit does not exist!"
|
||||
# actions:
|
||||
# - "actionbar::&cSorry %player%, but this kit does not exist!"
|
||||
|
||||
# Here another example with an auctionhouse plugin.
|
||||
# In here we only trigger the given message, if the player would type "/ah plugin".
|
||||
# Normally it would print out the "command is blocked" message, because PAT would have blocked it in our case.
|
||||
# Therefore, we can also assign a custom response message to it.
|
||||
# ---
|
||||
#example-with-auctionhouse:
|
||||
# triggers:
|
||||
# - "ah plugin"
|
||||
# message:
|
||||
# - "&cThis sub-command does not exist. Please type: &e/ah help"
|
||||
# actions:
|
||||
# - "console::say That's not nice %player%!"
|
||||
# - "effect::BLINDNESS::45::1"
|
||||
# - "sound::ENTITY_ENDER_DRAGON_GROWL::1.0::1.0"
|
||||
# - "title::&cHey!::&cYou can't do that %player%!::5::20::5"
|
||||
# - "actionbar::&cNop, sorry %player%"
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Proxy examples</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
# ____ ___ __ _ ______ __
|
||||
# / __ \_________ / | ____ / /_(_)_ __/___ _/ /_
|
||||
# / /_/ / ___/ __ \/ /| | / __ \/ __/ / / / / __ `/ __ \
|
||||
# / ____/ / / /_/ / ___ |/ / / / /_/ / / / / /_/ / /_/ /
|
||||
# /_/ /_/ \____/_/ |_/_/ /_/\__/_/ /_/ \__,_/_.___/
|
||||
# custom-responses.yml
|
||||
#
|
||||
# Here you can configure a few of the blocked commands a bit further.
|
||||
# But what exactly is this here? Every command that would normally respond with the typical "command is blocked" message, can be configured in here!
|
||||
# And how does it work? It's simple. You just provide the a trigger of the command that would be normally blocked.
|
||||
# Commands that would normally work won't send the messages you have set here.
|
||||
# This way PAT can offer you full control over certain commands and their normal responses.
|
||||
# What are these action section at each block?
|
||||
# This is an additional feature to make your responses much more alive.
|
||||
# Example actions that can be used are the following:
|
||||
# Execute console command:
|
||||
# Syntax: console::command
|
||||
# Example: console::send %player% fallback
|
||||
# Execute player command:
|
||||
# Syntax: execute::command
|
||||
# Example: execute::help
|
||||
# Send actionbar:
|
||||
# Syntax: actionbar::text
|
||||
# Example: actionbar::&cThis is not cool %player%!
|
||||
# Send title:
|
||||
# Syntax: title::title::subtitle::5::20::5
|
||||
# Example: title::&aTest title::&cHello %player%!
|
||||
|
||||
# Here are a few examples:
|
||||
|
||||
# Example with kits.
|
||||
# In here we only trigger the given message, if the player would type "/kit ...".
|
||||
# If this command would work through sub-arguments, then the player would only able to execute the command with the
|
||||
# listed sub-arguments assigned to it. Everything else will result with the set message in there.
|
||||
# --
|
||||
#example-with-kits:
|
||||
# triggers:
|
||||
# - "kit *"
|
||||
# message:
|
||||
# - "&cThis kit does not exist!"
|
||||
# actions:
|
||||
# - "actionbar::&cSorry %player%, but this kit does not exist!"
|
||||
|
||||
# Here another example with an auctionhouse plugin.
|
||||
# In here we only trigger the given message, if the player would type "/ah plugin".
|
||||
# Normally it would print out the "command is blocked" message, because PAT would have blocked it in our case.
|
||||
# Therefore, we can also assign a custom response message to it.
|
||||
# ---
|
||||
#example-with-auctionhouse:
|
||||
# triggers:
|
||||
# - "ah plugin"
|
||||
# message:
|
||||
# - "&cThis sub-command does not exist. Please type: &e/ah help"
|
||||
# actions:
|
||||
# - "console::say That's not nice %player%!"
|
||||
# - "title::Hey!::You can't do that %player%!::30::3000::30"
|
||||
# - "actionbar::Nop, sorry %player%"
|
||||
```
|
||||
</details>
|
||||
|
||||
#####
|
||||
# **N**EGATE COMMANDS
|
||||
It's not a must to write each and every possible sub-argument by hand. The same goes for commands in general.
|
||||
You can negate them with the help of the negation operator (``!``).
|
||||
|
||||
**
|
||||
|
||||
<details>
|
||||
<summary>example</summary>
|
||||
|
||||
```yaml
|
||||
# Allows /gamemode and all of its sub-arguments
|
||||
# except "/gamemode creative"
|
||||
- "gamemode"
|
||||
- "!gamemode creative"
|
||||
- '!gamemode toggle'
|
||||
```
|
||||
|
||||
```yaml
|
||||
# Allows all commands, except /anvil
|
||||
- "*"
|
||||
- "!anvil"
|
||||
```
|
||||
</details>
|
||||
|
||||
#####
|
||||
# **A**UTO-ADD ALL PLUGIN COMMANDS
|
||||
Sometimes it's so annoying to add all commands from a certain plugin by hand. That's why ProAntiTab offers the possebility to simply add all commands from a certain plugin with a simple shortcut.
|
||||
|
||||
You can simply add ``plugin=<plugin-name>`` to add all commands from a plugin automatically.
|
||||
**Only works for standalone Spigot (+Forks) servers**
|
||||
|
||||
<details>
|
||||
<summary>example</summary>
|
||||
|
||||
```yaml
|
||||
# Allows all Essentials commands except /anvil.
|
||||
# /gamemode is limited to only two sub-arguments
|
||||
- "plugin=essentials"
|
||||
- "!anvil"
|
||||
- "gamemode creative"
|
||||
- "gamemode survival"
|
||||
```
|
||||
</details>
|
||||
|
||||
######
|
||||
# **B**LOCK ON SPECIFIC SERVERS
|
||||
If you use ProAntiTab on a network, you can pretty easily manage on what servers what commands should exist. Everything can be handled via the proxy and does not require additional maintenance on the backend servers.
|
||||
|
||||
For this, just follow the official [setup](https://github.com/RayzsYT/ProAntiTab/wiki/How-to-setup#proxy--spigot-eg-bungeecord--spigot) and [how-to](https://github.com/RayzsYT/ProAntiTab/wiki/How-to#introduction) guide, which can be both found on the [Github wiki](https://github.com/RayzsYT/ProAntiTab/wiki).
|
||||
|
||||
######
|
||||
# **G**ROUP SYSYTEM
|
||||
The PAT group system allows you to allow certain commands only for a certain group of people. PAT group commands are mainly for **whitelisting** commands, can merge with other groups, and so on.
|
||||
|
||||
They can also be used to blacklist commands by negating the commands inside there. But for this to work, the option `allow-group-overruling` inside the `config.yml` needs to be enabled.
|
||||
|
||||
How to use the PAT group system in general can be seen on the [Github wiki](https://github.com/RayzsYT/ProAntiTab/wiki/How-to#use-the-group-system).
|
||||
|
||||
######
|
||||
# **P**LACEHOLDERAPI & PAPIPROXYBRIDGE SUPPORT
|
||||
Customization and uniqueness is an important factor for many server owners. That's why PAT offers you the possebility to edit and use many of its placeholders with the widely spreaded plugin [PlaceholderAPI](https://www.spigotmc.org/resources/6245/). Accessing those placeholders on the proxy isn't a problem either. With the support of the addtional plugin [PAPIProxyBridge](https://www.spigotmc.org/resources/108415/), PAT's placeholders are even accessable on your proxy server.
|
||||
<details>
|
||||
<summary>Available placeholders</summary>
|
||||
|
||||
```yaml
|
||||
# Some general Placeholders to work with:
|
||||
# %pat_general_user% = Get the name of the user who receives this message.
|
||||
# %pat_general_version_current% = Get current version name of PAT.
|
||||
# %pat_general_version_newest% = Get newest version name of PAT.
|
||||
|
||||
# Placeholders of some of the messages in the config.yml:
|
||||
# %pat_message_unknowncommand% = Get the "unknown command"-message from the config.yml of PAT. [cancel-blocked-command]
|
||||
# %pat_message_blocked% = Get the "command blocked"-message from the config.yml of PAT. [custom-unknown-command]
|
||||
|
||||
# Placeholders to list all commands:
|
||||
# %pat_list_size_commands% = Get the amount of all listed commands.
|
||||
# %pat_list_commands% = Get all listed commands.
|
||||
# %pat_list_sorted_commands% = Get all listed commands in alphabetic order. (A-Z)
|
||||
# %pat_list_reversed_groups% = Get all listed commands in reversed alphabetic order. (Z-A)
|
||||
|
||||
# Placeholders to list all commands of a group: (replace 'xxx' with the group-name)
|
||||
# %pat_list_size_commands_group_xxx% = Get the amount of all commands of a group.
|
||||
# %pat_list_commands_group_xxx% = Get all commands of a group.
|
||||
# %pat_list_sorted_commands_group_xxx% = Get all commands of a group in alphabetic order. (A-Z)
|
||||
# %pat_list_reversed_commands_group_xxx% = Get all commands of a group in reversed alphabetic order. (Z-A)
|
||||
|
||||
# Placeholders to list all groups:
|
||||
# %pat_list_size_groups% = Get the amount of all available groups.
|
||||
# %pat_list_groups% = Get all groups.
|
||||
# %pat_list_sorted_groups% = Get all groups in alphabetic order. (A-Z)
|
||||
# %pat_list_reversed_groups% = Get all groups in reversed alphabetic order. (Z-A)
|
||||
```
|
||||
</details>
|
||||
|
||||
###
|
||||
|
||||
# **M**INIMESSAGE SUPPORT
|
||||
## 
|
||||
##### You want to design your messages more unique? We got you covered! *(works on 1.17 server and above)*
|
||||
*([Click here to see the documentation for the format](https://docs.advntr.dev/minimessage/format.html#)*)
|
||||
|
||||
Look at those few examples to see what kind of possibilities awaits you:
|
||||
<details>
|
||||
<summary>example 1</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
cancel-blocked-commands:
|
||||
enabled: true
|
||||
message: '<hover:show_text:"&cBlocked command: &4&o%command%">&cThis command is &4&lBLOCKED&c!'
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>example 2</summary>
|
||||
|
||||
|
||||
```yaml
|
||||
cancel-blocked-commands:
|
||||
enabled: true
|
||||
message: '&cThis command is blocked! <click:suggest_command:/help>&7Click here to get a view of all available commands instead.'
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
||||
</details>
|
||||
|
||||
|
||||
######
|
||||
# **H**OW TO SETUP?
|
||||
Despite of the fact that ProAntiTab is pretty easy to use, the setup is slidely different for each server engine.
|
||||
It normally is already enough to simply load ProAntiTab on the certain server you wanna use it, but in order to use ProAntiTab with all its features, its recommended to follow the [official setup guide on the Github wiki](https://github.com/RayzsYT/ProAntiTab/wiki/How-to-setup).
|
||||
|
||||
**Please feel free to join the [Discord](https://www.rayzs.de/discord) server to request for help if the instruction is unclear or too complicated. ^^**
|
||||
|
||||
|
||||
#
|
||||
# **H**OW TO ALLOW COMMANDS?
|
||||
[Please check out the wiki to get an idea on how PAT works and can be used.](https://github.com/RayzsYT/ProAntiTab/wiki/How-to)
|
||||
|
||||
If you want to bypass all blocked commands, simply give yourself the following permission: **proantitab.bypass**
|
||||
|
||||
Following permission is required to execute all listed commands within a certain group: **proantitab.group.<command>**
|
||||
|
||||
######
|
||||
# **C**OMMANDS & PERMISSIONS
|
||||
All commands and their permissions are listed on the [documentation](https://www.spigotmc.org/resources/113172/field?field=documentation) page at the very buttom.
|
||||
|
||||
######
|
||||
# **C**ONFIGURATION FILE
|
||||
|
||||
<details>
|
||||
<summary>Bukkit/Spigot</summary>
|
||||
|
||||
[config.yml](https://github.com/RayzsYT/ProAntiTab/blob/v2.0.1/src/main/resources/files/bukkit-config.yml)
|
||||
<br>
|
||||
[storage.yml](https://github.com/RayzsYT/ProAntiTab/blob/v2.0.1/src/main/resources/files/bukkit-storage.yml)
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Proxy (Bungeecord/Velocity)</summary>
|
||||
|
||||
[config.yml](https://github.com/RayzsYT/ProAntiTab/blob/v2.0.1/src/main/resources/files/proxy-config.yml)
|
||||
<br>
|
||||
[storage.yml](https://github.com/RayzsYT/ProAntiTab/blob/v2.0.1/src/main/resources/files/proxy-storage.yml)
|
||||
|
||||
</details>
|
||||
|
||||
######
|
||||
## **bStats**
|
||||
[](https://bstats.org/plugin/bukkit/proantitab%20-%20spigot/20089)
|
||||
|
||||
[](https://bstats.org/plugin/bungeecord/proantitab%20-%20bungeecord/20090)
|
||||
|
||||
[](https://bstats.org/plugin/velocity/proantitab%20-%20velocity/21638)
|
||||
|
||||
<center>
|
||||
|
||||
[](https://www.rayzs.de/discord)
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
<groupId>de.rayzs.pat</groupId>
|
||||
<artifactId>ProAntiTab</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<version>2.3.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@@ -100,7 +100,7 @@
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -192,7 +192,7 @@
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>3.1.1-SNAPSHOT</version>
|
||||
<version>3.3.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -227,35 +227,35 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.25.0</version>
|
||||
<version>4.26.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.25.0</version>
|
||||
<version>4.26.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-api</artifactId>
|
||||
<version>4.3.3</version>
|
||||
<version>4.4.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||
<version>4.3.4</version>
|
||||
<version>4.4.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.3.4</version>
|
||||
<version>4.4.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -276,7 +276,7 @@
|
||||
<dependency>
|
||||
<groupId>com.viaversion</groupId>
|
||||
<artifactId>viaversion-api</artifactId>
|
||||
<version>LATEST</version>
|
||||
<version>5.7.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -291,6 +291,16 @@
|
||||
|
||||
<build>
|
||||
<finalName>IgnoreThisJar</finalName>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<excludes>
|
||||
<exclude>*.txt</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -317,8 +327,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -7,7 +7,7 @@ import de.rayzs.pat.utils.Reflection;
|
||||
|
||||
public class CustomServerBrand {
|
||||
|
||||
public static final String CHANNEL_NAME = Reflection.getMinor() < 13 ? "MC|Brand" : "minecraft:brand";
|
||||
public static final String CHANNEL_NAME = Reflection.isBefore(1, 13) ? "MC|Brand" : "minecraft:brand";
|
||||
private static final ServerBrand SERVER_BRAND = Reflection.isVelocityServer() ? new VelocityServerBrand() : Reflection.isProxyServer() ? new BungeeServerBrand() : new BukkitServerBrand();
|
||||
|
||||
public static void initialize() { refreshTask(); }
|
||||
|
||||
@@ -30,7 +30,7 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
|
||||
if (Reflection.isWeird()) {
|
||||
|
||||
NO_PREP_CHANNELS = Reflection.getMinor() >= 22 || (Reflection.getMinor() == 21 && Reflection.getRelease() >= 7);
|
||||
NO_PREP_CHANNELS = Reflection.isAtLeast(1, 21, 7);
|
||||
|
||||
if (brandPayloadClass == null)
|
||||
brandPayloadClass = Reflection.getClass("net.minecraft.network.protocol.common.custom.BrandPayload");
|
||||
|
||||
@@ -1,41 +1,101 @@
|
||||
package de.rayzs.pat.api.communication;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.scheduler.*;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class BackendUpdater {
|
||||
|
||||
private BackendUpdater() {}
|
||||
|
||||
|
||||
private static PATSchedulerTask TASK;
|
||||
private static boolean CONNECTED = false,
|
||||
WAITING = false;
|
||||
|
||||
private static final long SCHEDULER_PERIOD_TIME = 20 * 10;
|
||||
|
||||
public static void handle() {
|
||||
if(isRunning() || !shouldRun() || !Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) return;
|
||||
if (!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isRunning() || !canRun()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public static boolean isRunning() {
|
||||
return TASK != null && TASK.isActive();
|
||||
public static void restart() {
|
||||
stop();
|
||||
handle();
|
||||
}
|
||||
|
||||
public static void start() {
|
||||
if(isRunning()) return;
|
||||
public static void receivedKeepAlivePacket() {
|
||||
WAITING = false;
|
||||
CONNECTED = true;
|
||||
}
|
||||
|
||||
public static boolean isConnected() {
|
||||
return CONNECTED;
|
||||
}
|
||||
|
||||
private static void start() {
|
||||
if (isRunning()) return;
|
||||
|
||||
TASK = PATScheduler.createScheduler(() -> {
|
||||
if (shouldRun())
|
||||
Communicator.sendRequest();
|
||||
else
|
||||
|
||||
if (!canRun()) {
|
||||
stop();
|
||||
}, 5, 20);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CONNECTED) {
|
||||
|
||||
if (WAITING) {
|
||||
disconnect();
|
||||
|
||||
Communicator.Backend2Proxy.sendIdentityRequest();
|
||||
return;
|
||||
}
|
||||
|
||||
WAITING = true;
|
||||
|
||||
Communicator.Backend2Proxy.sendKeepAliveRequest();
|
||||
return;
|
||||
}
|
||||
|
||||
Communicator.Backend2Proxy.sendIdentityRequest();
|
||||
}, 20, SCHEDULER_PERIOD_TIME);
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
if(TASK == null || !TASK.isActive()) return;
|
||||
TASK.cancelTask();
|
||||
TASK = null;
|
||||
disconnect();
|
||||
|
||||
if (isRunning()) {
|
||||
TASK.cancelTask();
|
||||
TASK = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldRun() {
|
||||
int onlinePlayerSize = Bukkit.getOnlinePlayers().size();
|
||||
private static void disconnect() {
|
||||
CONNECTED = false;
|
||||
WAITING = false;
|
||||
}
|
||||
|
||||
private static boolean isRunning() {
|
||||
return TASK != null && TASK.isActive();
|
||||
}
|
||||
|
||||
private static boolean canRun() {
|
||||
if (!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final int onlinePlayerSize = Bukkit.getOnlinePlayers().size();
|
||||
return onlinePlayerSize >= 1;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package de.rayzs.pat.api.communication;
|
||||
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
|
||||
public interface Client {
|
||||
String CHANNEL_NAME = "pat:channel";
|
||||
void send(Object packet);
|
||||
void reload();
|
||||
void send(CommunicationPackets.PATPacket packet);
|
||||
}
|
||||
@@ -1,253 +1,356 @@
|
||||
package de.rayzs.pat.api.communication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import de.rayzs.pat.api.communication.client.impl.BungeeClientInfo;
|
||||
import de.rayzs.pat.api.communication.client.impl.VelocityClientInfo;
|
||||
import de.rayzs.pat.api.communication.impl.BukkitClient;
|
||||
import de.rayzs.pat.api.communication.impl.BungeeClient;
|
||||
import de.rayzs.pat.api.communication.impl.VelocityClient;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.group.TinyGroup;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
|
||||
public class Communicator {
|
||||
|
||||
private static final Client CLIENT =
|
||||
Reflection.isVelocityServer() ? new VelocityClient()
|
||||
: Reflection.isProxyServer() ? new BungeeClient()
|
||||
: new BukkitClient();
|
||||
|
||||
private static final UUID SERVER_ID = UUID.randomUUID();
|
||||
private static Communicator instance = null;
|
||||
|
||||
public static final List<ClientInfo> CLIENTS = new ArrayList<>();
|
||||
public static void initialize(final Client client) {
|
||||
if (instance != null) {
|
||||
Logger.warning("Communicator instance is already initialized!");
|
||||
return;
|
||||
}
|
||||
|
||||
public static int SERVER_DATA_SYNC_COUNT = 0;
|
||||
public static long LAST_DATA_UPDATE = System.currentTimeMillis(),
|
||||
LAST_SENT_REQUEST = 0,
|
||||
LAST_BUKKIT_SYNC = System.currentTimeMillis();
|
||||
|
||||
public static void sendPacket(Object packet) {
|
||||
CLIENT.send(packet);
|
||||
instance = new Communicator(client);
|
||||
}
|
||||
|
||||
public static void sendPacket(ClientInfo clientInfo, Object packet) {
|
||||
clientInfo.sendBytes(CommunicationPackets.convertToBytes(packet));
|
||||
public static Communicator get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void receiveInformation(String serverName, Object packet) {
|
||||
ClientInfo client = getClientByName(serverName);
|
||||
|
||||
if (packet instanceof CommunicationPackets.RequestPacket) {
|
||||
public static class Backend2Proxy {
|
||||
|
||||
CommunicationPackets.RequestPacket requestPacket = (CommunicationPackets.RequestPacket) packet;
|
||||
private Backend2Proxy() {}
|
||||
|
||||
if (!requestPacket.isToken(Storage.TOKEN))
|
||||
return;
|
||||
|
||||
if (client == null) {
|
||||
client = Reflection.isVelocityServer()
|
||||
? new VelocityClientInfo(requestPacket.getServerId(), serverName)
|
||||
: new BungeeClientInfo(requestPacket.getServerId(), serverName);
|
||||
|
||||
CLIENTS.add(client);
|
||||
}
|
||||
|
||||
if (!client.compareId(requestPacket.getServerId()))
|
||||
client.setId(requestPacket.getServerId());
|
||||
|
||||
syncData(client.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet instanceof CommunicationPackets.UpdateCommandsPacket) {
|
||||
if (Reflection.isProxyServer())
|
||||
return;
|
||||
|
||||
CommunicationPackets.UpdateCommandsPacket updateCommandsPacket = (CommunicationPackets.UpdateCommandsPacket) packet;
|
||||
BukkitLoader.handleUpdateCommandsPacket(updateCommandsPacket);
|
||||
}
|
||||
|
||||
if (packet instanceof CommunicationPackets.ForcePermissionResetPacket) {
|
||||
if (Reflection.isProxyServer())
|
||||
return;
|
||||
|
||||
CommunicationPackets.ForcePermissionResetPacket permissionResetPacket = (CommunicationPackets.ForcePermissionResetPacket) packet;
|
||||
if (!permissionResetPacket.isToken(Storage.TOKEN))
|
||||
return;
|
||||
|
||||
if (permissionResetPacket.hasTarget())
|
||||
PermissionUtil.setPlayerPermissions(permissionResetPacket.getTargetUUID());
|
||||
else
|
||||
PermissionUtil.reloadPermissions();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet instanceof CommunicationPackets.BackendDataPacket) {
|
||||
CommunicationPackets.BackendDataPacket backendDataPacket = (CommunicationPackets.BackendDataPacket) packet;
|
||||
if (!backendDataPacket.isToken(Storage.TOKEN))
|
||||
return;
|
||||
|
||||
Storage.SERVER_NAME = backendDataPacket.getServerName();
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet instanceof CommunicationPackets.FeedbackPacket) {
|
||||
CommunicationPackets.FeedbackPacket feedbackPacket = (CommunicationPackets.FeedbackPacket) packet;
|
||||
if (!feedbackPacket.isToken(Storage.TOKEN))
|
||||
return;
|
||||
|
||||
String serverId = feedbackPacket.getServerId();
|
||||
|
||||
if (client == null) {
|
||||
client = Reflection.isVelocityServer()
|
||||
? new VelocityClientInfo(feedbackPacket.getServerId(), serverName)
|
||||
: new BungeeClientInfo(feedbackPacket.getServerId(), serverName);
|
||||
|
||||
CLIENTS.add(client);
|
||||
}
|
||||
|
||||
if (!client.compareId(feedbackPacket.getServerId()))
|
||||
client.setId(feedbackPacket.getServerId());
|
||||
|
||||
if (client.hasSentFeedback())
|
||||
return;
|
||||
|
||||
client.setFeedback(true);
|
||||
client.syncTime();
|
||||
SERVER_DATA_SYNC_COUNT++;
|
||||
|
||||
CommunicationPackets.BackendDataPacket backendDataPacket = new CommunicationPackets.BackendDataPacket(Storage.TOKEN, serverId, serverName);
|
||||
sendPacket(client, backendDataPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet instanceof CommunicationPackets.PacketBundle) {
|
||||
CommunicationPackets.PacketBundle packetBundle = (CommunicationPackets.PacketBundle) packet;
|
||||
if (!packetBundle.isToken(Storage.TOKEN) || !packetBundle.isId(SERVER_ID.toString()))
|
||||
return;
|
||||
|
||||
Storage.USE_VELOCITY = packetBundle.isVelocity();
|
||||
LAST_BUKKIT_SYNC = System.currentTimeMillis();
|
||||
BukkitLoader.synchronize(packetBundle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncData() {
|
||||
syncData(null);
|
||||
}
|
||||
|
||||
public static void syncData(String serverId) {
|
||||
if (Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED)
|
||||
return;
|
||||
|
||||
LAST_DATA_UPDATE = System.currentTimeMillis();
|
||||
ClientInfo clientInfo;
|
||||
|
||||
if(serverId == null) {
|
||||
SERVER_DATA_SYNC_COUNT = 0;
|
||||
CLIENTS.forEach(currentClient -> syncData(currentClient.getId()));
|
||||
return;
|
||||
|
||||
} else {
|
||||
clientInfo = getClientById(serverId);
|
||||
|
||||
if (clientInfo != null)
|
||||
clientInfo.setFeedback(false);
|
||||
|
||||
SERVER_DATA_SYNC_COUNT = Math.max(0, SERVER_DATA_SYNC_COUNT -1);
|
||||
}
|
||||
|
||||
CommunicationPackets.CommandsPacket commandsPacket = new CommunicationPackets.CommandsPacket();
|
||||
CommunicationPackets.GroupsPacket groupsPacket;
|
||||
CommunicationPackets.PacketBundle bundle;
|
||||
List<String> commands = new ArrayList<>();
|
||||
String tempServerName = "";
|
||||
|
||||
if (clientInfo != null && clientInfo.getName() != null) {
|
||||
tempServerName = clientInfo.getName();
|
||||
|
||||
if (!Storage.Blacklist.isIgnoredServer(tempServerName))
|
||||
commands.addAll(Storage.Blacklist.getBlacklist().getCommands());
|
||||
|
||||
List<GeneralBlacklist> serverBlacklists = Storage.Blacklist.getServerBlacklists(clientInfo.getName());
|
||||
serverBlacklists.stream().filter(serverBlacklist ->
|
||||
serverBlacklist != null && serverBlacklist.getCommands() != null
|
||||
).forEach(serverBlacklist ->
|
||||
commands.addAll(serverBlacklist.getCommands())
|
||||
public static void sendIdentityRequest() {
|
||||
get().send2Proxy(
|
||||
new CommunicationPackets.Backend2Proxy.IdentityRequestPacket(get().getId())
|
||||
);
|
||||
}
|
||||
|
||||
final String serverName = tempServerName;
|
||||
List<TinyGroup> groups = new ArrayList<>();
|
||||
|
||||
TinyGroup tinyGroup;
|
||||
for (Group group : GroupManager.getGroups()) {
|
||||
if (groups.stream().anyMatch(cTG -> cTG.getGroupName().equals(group.getGroupName())))
|
||||
continue;
|
||||
|
||||
tinyGroup = new TinyGroup(group.getGroupName(), group.getPriority(), group.getAllCommands(serverName));
|
||||
for (GroupBlacklist groupBlacklist : group.getAllServerGroupBlacklist(serverName))
|
||||
tinyGroup.addAll(groupBlacklist.getCommands());
|
||||
|
||||
groups.add(tinyGroup);
|
||||
public static void sendKeepAliveRequest() {
|
||||
get().send2Proxy(
|
||||
new CommunicationPackets.Backend2Proxy.KeepAlivePacket()
|
||||
);
|
||||
}
|
||||
|
||||
groupsPacket = new CommunicationPackets.GroupsPacket(groups);
|
||||
commandsPacket.setTurnBlacklistToWhitelist(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED);
|
||||
commandsPacket.setCommands(commands);
|
||||
|
||||
bundle = new CommunicationPackets.PacketBundle(Storage.TOKEN, serverId, commandsPacket, groupsPacket);
|
||||
clientInfo.sendBytes(CommunicationPackets.convertToBytes(bundle));
|
||||
|
||||
PATEventHandler.callSentSyncEvents(bundle, serverName);
|
||||
}
|
||||
|
||||
public static void sendRequest() {
|
||||
if(System.currentTimeMillis() - LAST_SENT_REQUEST >= 5000) {
|
||||
LAST_SENT_REQUEST = System.currentTimeMillis();
|
||||
sendPacket(new CommunicationPackets.RequestPacket(Storage.TOKEN, SERVER_ID.toString()));
|
||||
public static class Proxy2Backend {
|
||||
|
||||
private Proxy2Backend() {}
|
||||
|
||||
// Update commands for all players
|
||||
public static void sendUpdateCommand() {
|
||||
get().send2AllClients(
|
||||
new CommunicationPackets.Proxy2Backend.UpdatePacket(null)
|
||||
);
|
||||
}
|
||||
|
||||
// Update commands for a certain player.
|
||||
public static void sendUpdateCommand(UUID playerId, String serverName) {
|
||||
final ClientInfo clientInfo = get().clients.get(serverName);
|
||||
if (clientInfo == null) return;
|
||||
|
||||
clientInfo.send(
|
||||
new CommunicationPackets.Proxy2Backend.UpdatePacket(playerId)
|
||||
);
|
||||
}
|
||||
|
||||
public static void sendDataSync() {
|
||||
Communicator.get().lastSync = System.currentTimeMillis();
|
||||
|
||||
Communicator.get().send2AllClients(
|
||||
Communicator.get().constructDataSyncPacket()
|
||||
);
|
||||
}
|
||||
|
||||
// Sync data for one server
|
||||
public static void sendDataSync(String serverName) {
|
||||
final ClientInfo clientInfo = get().clients.get(serverName);
|
||||
if (clientInfo == null) return;
|
||||
|
||||
clientInfo.send(
|
||||
Communicator.get().constructDataSyncPacket()
|
||||
);
|
||||
}
|
||||
|
||||
// Sync data for all registered clients.
|
||||
public static void sendConsoleMessage(String serverName, String message) {
|
||||
final ClientInfo clientInfo = get().clients.get(serverName);
|
||||
if (clientInfo == null) return;
|
||||
|
||||
clientInfo.send(
|
||||
new CommunicationPackets.Proxy2Backend.ConsoleMessagePacket(message)
|
||||
);
|
||||
}
|
||||
|
||||
public static void sendExecutePlayerCommand(String serverName, UUID playerId, String command) {
|
||||
final ClientInfo clientInfo = get().clients.get(serverName);
|
||||
if (clientInfo == null) return;
|
||||
|
||||
clientInfo.send(
|
||||
new CommunicationPackets.Proxy2Backend.ExecutePlayerCommandPacket(playerId, command)
|
||||
);
|
||||
}
|
||||
|
||||
public static void sendExecuteConsoleCommand(String serverName, String command) {
|
||||
final ClientInfo clientInfo = get().clients.get(serverName);
|
||||
if (clientInfo == null) return;
|
||||
|
||||
clientInfo.send(
|
||||
new CommunicationPackets.Proxy2Backend.ExecuteConsoleCommandPacket(command)
|
||||
);
|
||||
}
|
||||
|
||||
public static void sendNotification(UUID playerId, String serverName, String command) {
|
||||
if (!Storage.ConfigSections.Settings.FORWARD_CONSOLE_NOTIFICATIONS.ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ClientInfo clientInfo = get().clients.get(serverName);
|
||||
if (clientInfo == null) return;
|
||||
|
||||
clientInfo.send(
|
||||
new CommunicationPackets.Proxy2Backend.NotificationPacket(playerId, command)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPermissionReset() {
|
||||
if(Reflection.isProxyServer())
|
||||
sendPacket(new CommunicationPackets.ForcePermissionResetPacket(Storage.TOKEN));
|
||||
|
||||
private final Client client;
|
||||
private final UUID id = UUID.randomUUID();
|
||||
|
||||
// Server name, ClientInfo
|
||||
private final Map<String, ClientInfo> clients = new HashMap<>();
|
||||
private final ExpireCache<String, ClientInfo> pendingClients = new ExpireCache<>(2, TimeUnit.SECONDS);
|
||||
|
||||
|
||||
private long lastReceivedKeepAliveResponse = System.currentTimeMillis();
|
||||
private long lastSync = System.currentTimeMillis();
|
||||
|
||||
|
||||
private Communicator(final Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public static void sendUpdateCommand() {
|
||||
sendPacket(new CommunicationPackets.UpdateCommandsPacket(Storage.TOKEN));
|
||||
|
||||
// BACKEND -> PROXY
|
||||
public void handleB2PPacket(String serverName, CommunicationPackets.PATPacket incomingPacket) {
|
||||
if (!incomingPacket.tokenMatches(Storage.TOKEN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Backend2Proxy.KeepAlivePacket packet) {
|
||||
final ClientInfo clientInfo = clients.get(serverName);
|
||||
if (clientInfo == null) return;
|
||||
|
||||
clientInfo.updateKeepAliveTime();
|
||||
clientInfo.send(new CommunicationPackets.Proxy2Backend.KeepAliveResponsePacket());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Backend2Proxy.IdentityRequestPacket packet) {
|
||||
final ClientInfo registeredClientInfo = clients.get(serverName);
|
||||
|
||||
final boolean exist = registeredClientInfo != null;
|
||||
final boolean same = exist && registeredClientInfo.getId().equals(packet.serverId());
|
||||
|
||||
if (!same) {
|
||||
final ClientInfo clientInfo = Reflection.isVelocityServer()
|
||||
? new VelocityClientInfo(packet.serverId(), serverName)
|
||||
: new BungeeClientInfo(packet.serverId(), serverName);
|
||||
|
||||
pendingClients.put(serverName, clientInfo);
|
||||
clientInfo.send(new CommunicationPackets.Proxy2Backend.IdentityPacket(packet.serverId(), serverName));
|
||||
} else {
|
||||
registeredClientInfo.send(new CommunicationPackets.Proxy2Backend.KeepAliveResponsePacket());
|
||||
registeredClientInfo.send(new CommunicationPackets.Proxy2Backend.IdentityPacket(packet.serverId(), serverName));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Backend2Proxy.IdentityResponsePacket packet) {
|
||||
final ClientInfo clientInfo = pendingClients.get(serverName);
|
||||
|
||||
if (clientInfo != null && clientInfo.getId().equals(packet.serverId())) {
|
||||
clientInfo.setId(packet.serverId());
|
||||
|
||||
|
||||
pendingClients.remove(serverName);
|
||||
clients.put(serverName, clientInfo);
|
||||
|
||||
|
||||
clientInfo.send(new CommunicationPackets.Proxy2Backend.KeepAliveResponsePacket());
|
||||
clientInfo.send( constructDataSyncPacket() );
|
||||
|
||||
clientInfo.updateSyncTime();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Backend2Proxy.DataSyncReceivedPacket packet) {
|
||||
final ClientInfo clientInfo = clients.get(serverName);
|
||||
if (clientInfo == null) return;
|
||||
|
||||
clientInfo.updateSyncTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void sendUpdateCommand(UUID targetUUID) {
|
||||
sendPacket(new CommunicationPackets.UpdateCommandsPacket(Storage.TOKEN, targetUUID));
|
||||
// PROXY -> BACKEND
|
||||
public void handleP2BPacket(CommunicationPackets.PATPacket incomingPacket) {
|
||||
if (!incomingPacket.tokenMatches(Storage.TOKEN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Proxy2Backend.KeepAliveResponsePacket packet) {
|
||||
|
||||
lastReceivedKeepAliveResponse = System.currentTimeMillis();
|
||||
BackendUpdater.receivedKeepAlivePacket();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Proxy2Backend.IdentityPacket packet) {
|
||||
Storage.SERVER_NAME = packet.serverName();
|
||||
|
||||
send2Proxy(new CommunicationPackets.Backend2Proxy.IdentityResponsePacket(id));
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Proxy2Backend.DataSyncPacket packet) {
|
||||
lastSync = System.currentTimeMillis();
|
||||
|
||||
send2Proxy(new CommunicationPackets.Backend2Proxy.DataSyncReceivedPacket());
|
||||
BukkitLoader.handleDataSyncPacket(packet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Proxy2Backend.UpdatePacket packet) {
|
||||
BukkitLoader.handleUpdateCommandsPacket(packet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Proxy2Backend.NotificationPacket packet) {
|
||||
BukkitLoader.handleNotificationPacket(packet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Proxy2Backend.ConsoleMessagePacket packet) {
|
||||
BukkitLoader.handleConsoleMessagePacket(packet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Proxy2Backend.ExecutePlayerCommandPacket packet) {
|
||||
BukkitLoader.handlePlayerExecuteCommandPacket(packet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (incomingPacket instanceof CommunicationPackets.Proxy2Backend.ExecuteConsoleCommandPacket packet) {
|
||||
BukkitLoader.handleConsoleExecuteCommandPacket(packet);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendFeedback() {
|
||||
sendPacket(new CommunicationPackets.FeedbackPacket(Storage.TOKEN, SERVER_ID.toString()));
|
||||
private void send2Proxy(CommunicationPackets.PATPacket packet) {
|
||||
if (Reflection.isProxyServer()) {
|
||||
Logger.warning("Cannot send B2P packet as proxy!");
|
||||
return;
|
||||
}
|
||||
|
||||
client.send(packet);
|
||||
}
|
||||
|
||||
public static Client getClient() {
|
||||
return CLIENT;
|
||||
private void send2Client(ClientInfo clientInfo, CommunicationPackets.PATPacket packet) {
|
||||
if (!Reflection.isProxyServer()) {
|
||||
Logger.warning("Cannot send P2B packet as backend!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (clientInfo == null || Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
clientInfo.send(packet);
|
||||
}
|
||||
|
||||
public static ClientInfo getClientById(String id) {
|
||||
return CLIENTS.isEmpty() ? null : CLIENTS.stream().filter(client -> client != null && client.compareId(id)).findFirst().orElse(null);
|
||||
private void send2AllClients(CommunicationPackets.PATPacket packet) {
|
||||
if (!Reflection.isProxyServer()) {
|
||||
Logger.warning("Cannot send P2B packet as backend!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
getClients().forEach(clientInfo -> {
|
||||
clientInfo.send(packet);
|
||||
});
|
||||
}
|
||||
|
||||
public static ClientInfo getClientByName(String name) {
|
||||
return CLIENTS.isEmpty() ? null : CLIENTS.stream().filter(client -> client != null && client.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
private CommunicationPackets.Proxy2Backend.DataSyncPacket constructDataSyncPacket() {
|
||||
return new CommunicationPackets.Proxy2Backend.DataSyncPacket(
|
||||
new CommunicationPackets.Proxy2Backend.DataSyncPacket.Messages(
|
||||
Storage.ConfigSections.Messages.PREFIX.PREFIX
|
||||
),
|
||||
new CommunicationPackets.Proxy2Backend.DataSyncPacket.AutoLowerCase(
|
||||
Storage.ConfigSections.Settings.AUTO_LOWERCASE_COMMANDS.ENABLED
|
||||
),
|
||||
new CommunicationPackets.Proxy2Backend.DataSyncPacket.UnknownCommand(
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED,
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.client.reload();
|
||||
}
|
||||
|
||||
public UUID getClientId(String serverName) {
|
||||
final ClientInfo clientInfo = clients.get(serverName);
|
||||
if (clientInfo == null) return null;
|
||||
|
||||
return clientInfo.getId();
|
||||
}
|
||||
|
||||
public boolean hasConnectedClients() {
|
||||
return !clients.isEmpty();
|
||||
}
|
||||
|
||||
public Set<ClientInfo> getClients() {
|
||||
return new HashSet<>(clients.values());
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getLastReceivedKeepAliveResponse() {
|
||||
return lastReceivedKeepAliveResponse;
|
||||
}
|
||||
|
||||
public long getLastSync() {
|
||||
return lastSync;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +1,62 @@
|
||||
package de.rayzs.pat.api.communication.client;
|
||||
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
import de.rayzs.pat.utils.TimeConverter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class ClientInfo {
|
||||
|
||||
private String id, name;
|
||||
private UUID id;
|
||||
private String serverName;
|
||||
|
||||
private boolean sentFeedback = false;
|
||||
private long syncTime = System.currentTimeMillis();
|
||||
private long syncTime = System.currentTimeMillis(),
|
||||
keepAliveTime = System.currentTimeMillis();
|
||||
|
||||
public ClientInfo(String serverId) {
|
||||
this.id = serverId;
|
||||
public ClientInfo(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ClientInfo(String serverId, String name) {
|
||||
this.id = serverId;
|
||||
this.name = name;
|
||||
public ClientInfo(UUID id, String name) {
|
||||
this.id = id;
|
||||
this.serverName = name;
|
||||
}
|
||||
|
||||
public abstract void sendBytes(byte[] bytes);
|
||||
public abstract void send(CommunicationPackets.PATPacket packet);
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setServerName(String name) {
|
||||
this.serverName = name;
|
||||
}
|
||||
|
||||
public void setId(String serverId) {
|
||||
this.id = serverId;
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
public boolean compareId(String id) {
|
||||
return this.id.equals(id);
|
||||
}
|
||||
|
||||
public void syncTime() {
|
||||
public void updateSyncTime() {
|
||||
syncTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public String getSyncTime() {
|
||||
public void updateKeepAliveTime() {
|
||||
keepAliveTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return System.currentTimeMillis() - keepAliveTime > 5000;
|
||||
}
|
||||
|
||||
public String getFormattedSyncTime() {
|
||||
return TimeConverter.calcAndGetTime(syncTime);
|
||||
}
|
||||
|
||||
public void setFeedback(boolean state) {
|
||||
this.sentFeedback = state;
|
||||
public String getFormattedLastReceivedKeepAlivePacketTime() {
|
||||
return TimeConverter.calcAndGetTime(keepAliveTime);
|
||||
}
|
||||
|
||||
public boolean hasSentFeedback() {
|
||||
return sentFeedback;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -2,25 +2,35 @@ package de.rayzs.pat.api.communication.client.impl;
|
||||
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import de.rayzs.pat.api.communication.Client;
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeeClientInfo extends ClientInfo {
|
||||
|
||||
public BungeeClientInfo(String serverId) {
|
||||
super(serverId);
|
||||
public BungeeClientInfo(UUID id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public BungeeClientInfo(String serverId, String name) {
|
||||
super(serverId, name);
|
||||
public BungeeClientInfo(UUID id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBytes(byte[] bytes) {
|
||||
ProxyServer.getInstance().getServers().entrySet().stream().filter(entry ->
|
||||
entry.getKey().equalsIgnoreCase(getName())
|
||||
).forEach(entry ->
|
||||
entry.getValue().sendData(Client.CHANNEL_NAME, bytes)
|
||||
);
|
||||
public void send(CommunicationPackets.PATPacket packet) {
|
||||
final byte[] preparedPacket = CommunicationPackets.preparePacket(packet, getId());
|
||||
|
||||
if (preparedPacket == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(getServerName());
|
||||
|
||||
if (serverInfo != null) {
|
||||
serverInfo.sendData(Client.CHANNEL_NAME, preparedPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,36 @@
|
||||
package de.rayzs.pat.api.communication.client.impl;
|
||||
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import de.rayzs.pat.api.communication.impl.VelocityClient;
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityClientInfo extends ClientInfo {
|
||||
|
||||
public VelocityClientInfo(String serverId) {
|
||||
super(serverId);
|
||||
public VelocityClientInfo(UUID id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public VelocityClientInfo(String serverId, String name) {
|
||||
super(serverId, name);
|
||||
public VelocityClientInfo(UUID id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBytes(byte[] bytes) {
|
||||
VelocityLoader.getServer().getAllServers().stream().filter(server ->
|
||||
server.getServerInfo().getName().equalsIgnoreCase(getName())
|
||||
).forEach(server ->
|
||||
server.sendPluginMessage(VelocityClient.getIdentifier(), bytes)
|
||||
);
|
||||
public void send(CommunicationPackets.PATPacket packet) {
|
||||
final byte[] preparedPacket = CommunicationPackets.preparePacket(packet, getId());
|
||||
|
||||
if (preparedPacket == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<RegisteredServer> optServer = VelocityLoader.getServer().getServer(getServerName());
|
||||
|
||||
optServer.ifPresent(registeredServer -> {
|
||||
registeredServer.sendPluginMessage(VelocityClient.getIdentifier(), preparedPacket);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.api.communication.impl;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.scheduler.PATScheduler;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
@@ -7,43 +8,96 @@ import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.api.communication.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.*;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class BukkitClient implements Client, PluginMessageListener {
|
||||
|
||||
private static final Server SERVER = Bukkit.getServer();
|
||||
private boolean registered = false;
|
||||
|
||||
public BukkitClient() {
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
if (!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
|
||||
if (registered) {
|
||||
unregister();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!registered) {
|
||||
register();
|
||||
}
|
||||
}
|
||||
|
||||
private void register() {
|
||||
registered = true;
|
||||
|
||||
SERVER.getMessenger().registerIncomingPluginChannel(BukkitLoader.getPlugin(), CHANNEL_NAME, this);
|
||||
SERVER.getMessenger().registerOutgoingPluginChannel(BukkitLoader.getPlugin(), CHANNEL_NAME);
|
||||
}
|
||||
|
||||
private void unregister() {
|
||||
registered = false;
|
||||
|
||||
SERVER.getMessenger().unregisterIncomingPluginChannel(BukkitLoader.getPlugin(), CHANNEL_NAME, this);
|
||||
SERVER.getMessenger().unregisterOutgoingPluginChannel(BukkitLoader.getPlugin(), CHANNEL_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object packet) {
|
||||
try {
|
||||
public void send(CommunicationPackets.PATPacket packet) {
|
||||
final byte[] preparedPacket = CommunicationPackets.preparePacket(packet);
|
||||
|
||||
SERVER.sendPluginMessage(BukkitLoader.getPlugin(), CHANNEL_NAME, CommunicationPackets.convertToBytes(packet));
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
if (preparedPacket == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player carrier = selectCarrier();
|
||||
if (carrier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PATScheduler.execute(() -> {
|
||||
if (!carrier.isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
carrier.sendPluginMessage(BukkitLoader.getPlugin(), CHANNEL_NAME, preparedPacket);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}, carrier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
|
||||
|
||||
if (!channel.equals(CHANNEL_NAME))
|
||||
if (!channel.equals(CHANNEL_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Object packetObj = CommunicationPackets.buildFromBytes(bytes);
|
||||
final Object packetObj = CommunicationPackets.readPacket(bytes);
|
||||
|
||||
if (!CommunicationPackets.isPacket(packetObj))
|
||||
if (!CommunicationPackets.isP2BPacket(packetObj)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PATScheduler.createScheduler(() -> Communicator.receiveInformation("proxy", packetObj));
|
||||
PATScheduler.createScheduler(() -> Communicator.get().handleP2BPacket((CommunicationPackets.PATPacket) packetObj));
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Player selectCarrier() {
|
||||
final Iterator<? extends Player> iterator = SERVER.getOnlinePlayers().iterator();
|
||||
return iterator.hasNext() ? iterator.next() : null;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.api.communication.impl;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
@@ -10,25 +11,39 @@ import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.api.communication.*;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeeClient implements Client, Listener {
|
||||
|
||||
private static final ProxyServer SERVER = ProxyServer.getInstance();
|
||||
|
||||
public BungeeClient() {
|
||||
|
||||
if (Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
SERVER.registerChannel(CHANNEL_NAME);
|
||||
SERVER.getPluginManager().registerListener(BungeeLoader.getPlugin(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object packet) {
|
||||
public void reload() {}
|
||||
|
||||
@Override
|
||||
public void send(CommunicationPackets.PATPacket packet) {
|
||||
final byte[] preparedPacket = CommunicationPackets.preparePacket(packet);
|
||||
|
||||
if (preparedPacket == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (ServerInfo serverInfo : ProxyServer.getInstance().getServers().values()) {
|
||||
|
||||
try {
|
||||
|
||||
serverInfo.sendData(CHANNEL_NAME, CommunicationPackets.convertToBytes(packet));
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
serverInfo.sendData(CHANNEL_NAME, preparedPacket);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,18 +51,26 @@ public class BungeeClient implements Client, Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onQueryReceive(PluginMessageEvent event) {
|
||||
if (!event.getTag().equalsIgnoreCase(CHANNEL_NAME))
|
||||
if (!event.getTag().equalsIgnoreCase(CHANNEL_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Server server = (Server) event.getSender();
|
||||
final String serverName = server.getInfo().getName();
|
||||
final UUID clientId = Communicator.get().getClientId(serverName);
|
||||
|
||||
if (!CommunicationPackets.isInitialPacket(event.getData()) && clientId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Object packetObj = CommunicationPackets.buildFromBytes(event.getData());
|
||||
|
||||
if (!CommunicationPackets.isPacket(packetObj))
|
||||
Object packetObj = CommunicationPackets.readPacket(event.getData(), clientId);
|
||||
if (!CommunicationPackets.isB2PPacket(packetObj)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Server server = (Server) event.getSender();
|
||||
Communicator.receiveInformation(server.getInfo().getName(), packetObj);
|
||||
Communicator.get().handleB2PPacket(serverName, (CommunicationPackets.PATPacket) packetObj);
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
|
||||
@@ -3,11 +3,13 @@ package de.rayzs.pat.api.communication.impl;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.api.communication.*;
|
||||
import com.velocitypowered.api.proxy.*;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityClient implements Client {
|
||||
|
||||
@@ -15,20 +17,33 @@ public class VelocityClient implements Client {
|
||||
private static final MinecraftChannelIdentifier IDENTIFIER = MinecraftChannelIdentifier.from(CHANNEL_NAME);
|
||||
|
||||
public VelocityClient() {
|
||||
|
||||
if (Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
SERVER.getChannelRegistrar().register(IDENTIFIER);
|
||||
SERVER.getEventManager().register(VelocityLoader.getInstance(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object packet) {
|
||||
public void reload() {}
|
||||
|
||||
@Override
|
||||
public void send(CommunicationPackets.PATPacket packet) {
|
||||
final byte[] preparedPacket = CommunicationPackets.preparePacket(packet);
|
||||
|
||||
if (preparedPacket == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (RegisteredServer registeredServer : SERVER.getAllServers()) {
|
||||
|
||||
try {
|
||||
|
||||
registeredServer.sendPluginMessage(IDENTIFIER, CommunicationPackets.convertToBytes(packet));
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
registeredServer.sendPluginMessage(IDENTIFIER, preparedPacket);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,16 +51,26 @@ public class VelocityClient implements Client {
|
||||
|
||||
@Subscribe
|
||||
public void onQueryReceive(PluginMessageEvent event) {
|
||||
if (event.getIdentifier() != IDENTIFIER)
|
||||
if (event.getIdentifier() != IDENTIFIER) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object packetObj = CommunicationPackets.buildFromBytes(event.getData());
|
||||
final ServerConnection server = (ServerConnection) event.getSource();
|
||||
final String serverName = server.getServerInfo().getName();
|
||||
final UUID clientId = Communicator.get().getClientId(serverName);
|
||||
|
||||
if (!CommunicationPackets.isPacket(packetObj))
|
||||
if (!CommunicationPackets.isInitialPacket(event.getData()) && clientId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object packetObj = CommunicationPackets.readPacket(event.getData(), clientId);
|
||||
|
||||
if (!CommunicationPackets.isB2PPacket(packetObj)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Communicator.get().handleB2PPacket(serverName, (CommunicationPackets.PATPacket) packetObj);
|
||||
|
||||
ServerConnection server = (ServerConnection) event.getSource();
|
||||
Communicator.receiveInformation(server.getServerInfo().getName(), packetObj);
|
||||
}
|
||||
|
||||
public static MinecraftChannelIdentifier getIdentifier() {
|
||||
|
||||
@@ -88,8 +88,8 @@ public class PATEventHandler {
|
||||
return event;
|
||||
}
|
||||
|
||||
public static SentSyncEvent callSentSyncEvents(CommunicationPackets.PacketBundle packetBundle, String serverName) {
|
||||
SentSyncEvent event = EmptyEvent.createEmptySentSyncEvent(packetBundle, serverName);
|
||||
public static SentSyncEvent callSentSyncEvents(CommunicationPackets.Proxy2Backend.DataSyncPacket dataSyncPacket, String serverName) {
|
||||
SentSyncEvent event = EmptyEvent.createEmptySentSyncEvent(dataSyncPacket, serverName);
|
||||
|
||||
for (PATEvent patEvent : EVENTS) {
|
||||
if(patEvent instanceof SentSyncEvent) {
|
||||
@@ -101,8 +101,8 @@ public class PATEventHandler {
|
||||
return event;
|
||||
}
|
||||
|
||||
public static ReceiveSyncEvent callReceiveSyncEvents(CommunicationPackets.PacketBundle packetBundle) {
|
||||
ReceiveSyncEvent event = EmptyEvent.createEmptyReceiveSyncEvent(packetBundle);
|
||||
public static ReceiveSyncEvent callReceiveSyncEvents(CommunicationPackets.Proxy2Backend.DataSyncPacket dataSyncPacket) {
|
||||
ReceiveSyncEvent event = EmptyEvent.createEmptyReceiveSyncEvent(dataSyncPacket);
|
||||
|
||||
for (PATEvent patEvent : EVENTS) {
|
||||
if(patEvent instanceof ReceiveSyncEvent) {
|
||||
@@ -133,8 +133,8 @@ public class PATEventHandler {
|
||||
};
|
||||
}
|
||||
|
||||
public static SentSyncEvent createEmptySentSyncEvent(CommunicationPackets.PacketBundle packetBundle, String serverName) {
|
||||
return new SentSyncEvent(null, packetBundle, serverName) {
|
||||
public static SentSyncEvent createEmptySentSyncEvent(CommunicationPackets.Proxy2Backend.DataSyncPacket dataSyncPacket, String serverName) {
|
||||
return new SentSyncEvent(null, dataSyncPacket, serverName) {
|
||||
@Override
|
||||
public void handle(SentSyncEvent event) {
|
||||
|
||||
@@ -142,8 +142,8 @@ public class PATEventHandler {
|
||||
};
|
||||
}
|
||||
|
||||
public static ReceiveSyncEvent createEmptyReceiveSyncEvent(CommunicationPackets.PacketBundle packetBundle) {
|
||||
return new ReceiveSyncEvent(null, packetBundle) {
|
||||
public static ReceiveSyncEvent createEmptyReceiveSyncEvent(CommunicationPackets.Proxy2Backend.DataSyncPacket dataSyncPacket) {
|
||||
return new ReceiveSyncEvent(null, dataSyncPacket) {
|
||||
@Override
|
||||
public void handle(ReceiveSyncEvent event) {
|
||||
|
||||
|
||||
@@ -5,19 +5,19 @@ import de.rayzs.pat.api.event.PATEvent;
|
||||
|
||||
public abstract class ReceiveSyncEvent extends PATEvent<ReceiveSyncEvent> {
|
||||
|
||||
private final CommunicationPackets.PacketBundle packetBundle;
|
||||
private final CommunicationPackets.Proxy2Backend.DataSyncPacket dataSyncPacket;
|
||||
|
||||
public ReceiveSyncEvent() {
|
||||
super(null);
|
||||
this.packetBundle = null;
|
||||
this.dataSyncPacket = null;
|
||||
}
|
||||
|
||||
public ReceiveSyncEvent(Object senderObj, CommunicationPackets.PacketBundle packetBundle) {
|
||||
public ReceiveSyncEvent(Object senderObj, CommunicationPackets.Proxy2Backend.DataSyncPacket dataSyncPacket) {
|
||||
super(senderObj);
|
||||
this.packetBundle = packetBundle;
|
||||
this.dataSyncPacket = dataSyncPacket;
|
||||
}
|
||||
|
||||
public CommunicationPackets.PacketBundle getPacketBundle() {
|
||||
return packetBundle;
|
||||
public CommunicationPackets.Proxy2Backend.DataSyncPacket getDataSyncPacket() {
|
||||
return dataSyncPacket;
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,18 @@ import de.rayzs.pat.api.event.PATEvent;
|
||||
|
||||
public abstract class SentSyncEvent extends PATEvent<SentSyncEvent> {
|
||||
|
||||
private final CommunicationPackets.PacketBundle packetBundle;
|
||||
private final CommunicationPackets.Proxy2Backend.DataSyncPacket dataSyncPacket;
|
||||
private final String serverName;
|
||||
|
||||
public SentSyncEvent() {
|
||||
super(null);
|
||||
this.packetBundle = null;
|
||||
this.dataSyncPacket = null;
|
||||
this.serverName = null;
|
||||
}
|
||||
|
||||
public SentSyncEvent(Object senderObj, CommunicationPackets.PacketBundle packetBundle, String serverName) {
|
||||
public SentSyncEvent(Object senderObj, CommunicationPackets.Proxy2Backend.DataSyncPacket dataSyncPacket, String serverName) {
|
||||
super(senderObj);
|
||||
this.packetBundle = packetBundle;
|
||||
this.dataSyncPacket = dataSyncPacket;
|
||||
this.serverName = serverName;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class SentSyncEvent extends PATEvent<SentSyncEvent> {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
public CommunicationPackets.PacketBundle getPacketBundle() {
|
||||
return packetBundle;
|
||||
public CommunicationPackets.Proxy2Backend.DataSyncPacket getDataSyncPacket() {
|
||||
return dataSyncPacket;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import io.netty.channel.*;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -19,7 +22,10 @@ public class BukkitPacketAnalyzer {
|
||||
private static final ExpireCache<UUID, Object> SENT_PACKET = new ExpireCache<>(2, TimeUnit.SECONDS);
|
||||
|
||||
private static final String HANDLER_NAME = "pat-bukkit-handler", PIPELINE_NAME = "packet_handler";
|
||||
private static final BukkitPacketHandler PACKET_HANDLER = Reflection.getMinor() >= 16 ? new ModernPacketHandler() : new LegacyPacketHandler();
|
||||
|
||||
private static final BukkitPacketHandler PACKET_HANDLER = Reflection.isAtLeast(1, 16) ? new ModernPacketHandler() : new LegacyPacketHandler();
|
||||
private static final BukkitPacketHandler COMMANDS_NODE_HANDLER = new ModernCommandsNodeHandler();
|
||||
|
||||
private static final HashMap<Player, String> PLAYER_INPUT_CACHE = new HashMap<>();
|
||||
|
||||
public static void injectAll() {
|
||||
@@ -42,7 +48,7 @@ public class BukkitPacketAnalyzer {
|
||||
}
|
||||
|
||||
public static boolean inject(Player player) {
|
||||
if (Storage.USE_VELOCITY)
|
||||
if (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED)
|
||||
return true;
|
||||
|
||||
try {
|
||||
@@ -59,20 +65,19 @@ public class BukkitPacketAnalyzer {
|
||||
BukkitPacketAnalyzer.INJECTED_PLAYERS.put(player.getUniqueId(), channel);
|
||||
} catch (IndexOutOfBoundsException indexOutOfBoundsException) {
|
||||
Reflection.toggleInjectionMethod();
|
||||
|
||||
Logger.info("Injection failed. Switching to secondary injection method.");
|
||||
boolean success = inject(player);
|
||||
|
||||
if (success) {
|
||||
Logger.info("Secondary injection method was successful.");
|
||||
} else {
|
||||
Logger.warning("Secondary injection method failed!");
|
||||
if (!success) {
|
||||
Logger.warning("Both injection methods failed! Please report this back to me on my Discord! (https://www.rayzs.de/discord)");
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
if (!Storage.ConfigSections.Settings.INJECTION_FAILED.SUPPRESS_EXCEPTIONS) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
@@ -81,7 +86,7 @@ public class BukkitPacketAnalyzer {
|
||||
}
|
||||
|
||||
public static void uninject(UUID uuid) {
|
||||
if (Storage.USE_VELOCITY)
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
return;
|
||||
|
||||
if (BukkitPacketAnalyzer.INJECTED_PLAYERS.containsKey(uuid)) {
|
||||
@@ -91,7 +96,7 @@ public class BukkitPacketAnalyzer {
|
||||
}
|
||||
|
||||
public static void uninject(Channel channel) {
|
||||
if (Storage.USE_VELOCITY)
|
||||
if (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED)
|
||||
return;
|
||||
|
||||
if (channel != null) {
|
||||
@@ -117,29 +122,35 @@ public class BukkitPacketAnalyzer {
|
||||
private static class PacketDecoder extends ChannelDuplexHandler {
|
||||
|
||||
private final Player player;
|
||||
private final CommandSender sender;
|
||||
|
||||
private PacketDecoder(Player player) {
|
||||
this.player = player;
|
||||
this.sender = CommandSenderHandler.from(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext channel, Object packetObj) {
|
||||
try {
|
||||
if (packetObj.getClass() != null) {
|
||||
String packetName = packetObj.getClass().getSimpleName();
|
||||
|
||||
if (!packetName.equals("PacketPlayInTabComplete") && !packetName.equals("ServerboundCommandSuggestionPacket")) {
|
||||
super.channelRead(channel, packetObj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player)) {
|
||||
|
||||
if (!PACKET_HANDLER.handleIncomingPacket(player, packetObj))
|
||||
return;
|
||||
|
||||
}
|
||||
if (packetObj.getClass() == null || Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
super.channelRead(channel, packetObj);
|
||||
return;
|
||||
}
|
||||
|
||||
String packetName = packetObj.getClass().getSimpleName();
|
||||
|
||||
if (!packetName.equals("PacketPlayInTabComplete") && !packetName.equals("ServerboundCommandSuggestionPacket")) {
|
||||
super.channelRead(channel, packetObj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(sender)) {
|
||||
|
||||
if (!PACKET_HANDLER.handleIncomingPacket(player, sender, packetObj))
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
super.channelRead(channel, packetObj);
|
||||
} catch (Throwable exception) { exception.printStackTrace(); }
|
||||
}
|
||||
@@ -148,32 +159,41 @@ public class BukkitPacketAnalyzer {
|
||||
public void write(ChannelHandlerContext channel, Object packetObj, ChannelPromise promise) {
|
||||
try {
|
||||
|
||||
if(packetObj.getClass() != null) {
|
||||
String packetName = packetObj.getClass().getSimpleName();
|
||||
if(packetObj.getClass() == null || Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
super.write(channel, packetObj, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!packetName.equals("PacketPlayOutTabComplete") && !packetName.equals("ClientboundCommandSuggestionsPacket")) {
|
||||
super.write(channel, packetObj, promise);
|
||||
final String packetName = packetObj.getClass().getSimpleName();
|
||||
final boolean isCommandsPacket = packetName.equals("ClientboundCommandsPacket");
|
||||
final boolean isTabCompletePacket = packetName.equals("PacketPlayOutTabComplete") || packetName.equals("ClientboundCommandSuggestionsPacket");
|
||||
|
||||
if (!isCommandsPacket && !isTabCompletePacket || PermissionUtil.hasBypassPermission(sender)) {
|
||||
super.write(channel, packetObj, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isCommandsPacket) {
|
||||
COMMANDS_NODE_HANDLER.handleOutgoingPacket(player, sender, packetObj);
|
||||
|
||||
super.write(channel, packetObj, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
Object sentPacketObj = SENT_PACKET.get(uuid);
|
||||
|
||||
if (sentPacketObj != null) {
|
||||
if (sentPacketObj == packetObj) {
|
||||
SENT_PACKET.remove(uuid);
|
||||
super.write(channel, sentPacketObj, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player)) {
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
Object sentPacketObj = SENT_PACKET.get(uuid);
|
||||
|
||||
if (sentPacketObj != null) {
|
||||
if (sentPacketObj == packetObj) {
|
||||
SENT_PACKET.remove(uuid);
|
||||
super.write(channel, sentPacketObj, promise);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PACKET_HANDLER.handleOutgoingPacket(player, packetObj))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PACKET_HANDLER.handleOutgoingPacket(player, sender, packetObj))
|
||||
return;
|
||||
|
||||
super.write(channel, packetObj, promise);
|
||||
|
||||
} catch (Throwable exception) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package de.rayzs.pat.api.netty.bukkit;
|
||||
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface BukkitPacketHandler {
|
||||
boolean handleIncomingPacket(Player player, Object packetObj) throws Exception;
|
||||
boolean handleOutgoingPacket(Player player, Object packetObj) throws Exception;
|
||||
boolean handleIncomingPacket(Player player, CommandSender sender, Object packetObj) throws Exception;
|
||||
boolean handleOutgoingPacket(Player player, CommandSender sender, Object packetObj) throws Exception;
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
@@ -19,7 +22,7 @@ import de.rayzs.pat.utils.Reflection;
|
||||
public class LegacyPacketHandler implements BukkitPacketHandler {
|
||||
|
||||
@Override
|
||||
public boolean handleIncomingPacket(Player player, Object packetObj) throws Exception {
|
||||
public boolean handleIncomingPacket(Player player, CommandSender sender, Object packetObj) throws Exception {
|
||||
Field stringField = Reflection.getFirstFieldByType(packetObj.getClass(), "String", Reflection.SearchOption.ENDS);
|
||||
if(stringField == null) {
|
||||
Logger.warning("Failed PacketAnalyze process! (#1)");
|
||||
@@ -32,11 +35,14 @@ public class LegacyPacketHandler implements BukkitPacketHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleOutgoingPacket(Player player, Object packetObj) throws Exception {
|
||||
public boolean handleOutgoingPacket(Player player, CommandSender sender, Object packetObj) throws Exception {
|
||||
final String rawInput = BukkitPacketAnalyzer.getPlayerInput(player);
|
||||
|
||||
if(rawInput == null)
|
||||
if(rawInput == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
String input = rawInput;
|
||||
boolean cancelsBeforeHand = false;
|
||||
@@ -47,7 +53,7 @@ public class LegacyPacketHandler implements BukkitPacketHandler {
|
||||
|
||||
input = input.substring(1);
|
||||
|
||||
final boolean doesBypassNamespace = Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player);
|
||||
final boolean doesBypassNamespace = Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(sender);
|
||||
final boolean spaces = input.contains(" ");
|
||||
|
||||
if (Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(input) && !doesBypassNamespace) {
|
||||
@@ -55,7 +61,7 @@ public class LegacyPacketHandler implements BukkitPacketHandler {
|
||||
}
|
||||
|
||||
if (!cancelsBeforeHand && !input.isEmpty()) {
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(player, StringUtils.getFirstArg(input));
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(sender, groups, StringUtils.getFirstArg(input));
|
||||
}
|
||||
|
||||
if (!cancelsBeforeHand) {
|
||||
@@ -100,7 +106,7 @@ public class LegacyPacketHandler implements BukkitPacketHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, cpy);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(sender, groups, cpy);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.rayzs.pat.api.netty.bukkit.handlers;
|
||||
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketHandler;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.utils.node.BukkitCommandNodeHelper;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
public class ModernCommandsNodeHandler implements BukkitPacketHandler {
|
||||
|
||||
public boolean handleIncomingPacket(Player player, CommandSender sender, Object packetObj) throws Exception {
|
||||
// Ignored
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleOutgoingPacket(Player player, CommandSender sender, Object packetObj) throws Exception {
|
||||
final BukkitCommandNodeHelper helper = new BukkitCommandNodeHelper(packetObj);
|
||||
|
||||
SubArguments.handleCommandNode(player.getUniqueId(), helper);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -28,7 +31,7 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
private static boolean modifiable = true;
|
||||
|
||||
@Override
|
||||
public boolean handleIncomingPacket(Player player, Object packetObj) throws Exception {
|
||||
public boolean handleIncomingPacket(Player player, CommandSender sender, Object packetObj) throws Exception {
|
||||
Field stringField = Reflection.getFirstFieldByType(packetObj.getClass(), "String", Reflection.SearchOption.ENDS);
|
||||
|
||||
if(stringField == null) {
|
||||
@@ -37,6 +40,8 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
}
|
||||
|
||||
String text = (String) stringField.get(packetObj);
|
||||
if (!text.isBlank() && text.charAt(0) != '/') text = '/' + text;
|
||||
|
||||
if (Storage.ConfigSections.Settings.PATCH_EXPLOITS.isMalicious(text)) {
|
||||
MessageTranslator.send(
|
||||
Bukkit.getConsoleSender(),
|
||||
@@ -57,13 +62,15 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleOutgoingPacket(Player player, Object packetObj) throws Exception {
|
||||
public boolean handleOutgoingPacket(Player player, CommandSender sender, Object packetObj) throws Exception {
|
||||
Object suggestionObj;
|
||||
String rawInput = BukkitPacketAnalyzer.getPlayerInput(player), input = rawInput;
|
||||
|
||||
if(input == null)
|
||||
if(input == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
boolean is121Packet = packetObj.getClass().getSimpleName().equals("ClientboundCommandSuggestionsPacket"),
|
||||
cancelsBeforeHand = false;
|
||||
@@ -77,7 +84,7 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
if(spaces > 0) input = split[0];
|
||||
}
|
||||
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(player, input);
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(sender, groups, input);
|
||||
|
||||
if (!cancelsBeforeHand)
|
||||
cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(input) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(input);
|
||||
@@ -98,7 +105,7 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
if ((input.isEmpty() || cancelsBeforeHand) && Reflection.isWeird())
|
||||
return false;
|
||||
|
||||
if (spaces >= 1 && cancelsBeforeHand || !BukkitLoader.isLoaded()) {
|
||||
if (spaces >= 1 && cancelsBeforeHand) {
|
||||
suggestions.clear();
|
||||
return true;
|
||||
}
|
||||
@@ -106,7 +113,7 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
if (spaces == 0) {
|
||||
suggestions.removeIf(suggestion -> {
|
||||
String command = getSuggestionFromEntry(suggestion);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, command);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(sender, groups, command);
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -149,7 +156,7 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
}
|
||||
|
||||
|
||||
if (Reflection.getMinor() < 17) {
|
||||
if (Reflection.isBefore(1, 17)) {
|
||||
Field suggestionsField = Reflection.getFieldsByType(packetObj.getClass(), "Suggestions", Reflection.SearchOption.ENDS).get(0);
|
||||
if (suggestionsField == null) return false;
|
||||
suggestionObj = suggestionsField.get(packetObj);
|
||||
@@ -171,7 +178,7 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(spaces >= 1 && cancelsBeforeHand || !BukkitLoader.isLoaded()) {
|
||||
if(spaces >= 1 && cancelsBeforeHand) {
|
||||
suggestions.getList().clear();
|
||||
return true;
|
||||
}
|
||||
@@ -180,7 +187,7 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
|
||||
suggestions.getList().removeIf(suggestion -> {
|
||||
String command = suggestion.getText();
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, command);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(sender, groups, command);
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
@@ -3,37 +3,35 @@ package de.rayzs.pat.api.netty.proxy;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
|
||||
import com.mojang.brigadier.tree.RootCommandNode;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.utils.node.CommandNodeHelper;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.node.ProxyCommandNodeHelper;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.packet.Commands;
|
||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
import net.md_5.bungee.protocol.packet.TabCompleteResponse;
|
||||
|
||||
public class BungeePacketAnalyzer {
|
||||
|
||||
@@ -41,7 +39,7 @@ public class BungeePacketAnalyzer {
|
||||
|
||||
private static final String HANDLER_NAME = "pat-bungee-handler", PIPELINE_NAME = "packet-decoder";
|
||||
private static final HashMap<ProxiedPlayer, Boolean> PLAYER_MODIFIED = new HashMap<>();
|
||||
private static final HashMap<ProxiedPlayer, String> PLAYER_INPUT_CACHE = new HashMap<>();
|
||||
private static final ExpireCache<UUID, String> PLAYER_INPUT_CACHE = new ExpireCache<>(5, TimeUnit.SECONDS);
|
||||
|
||||
private static final List<String> PLUGIN_COMMANDS = new ArrayList<>();
|
||||
|
||||
@@ -50,7 +48,7 @@ public class BungeePacketAnalyzer {
|
||||
private static List<String> PROXY_COMMANDS;
|
||||
|
||||
static {
|
||||
CommandNodeHelper.setDefaultSuggestionProvider(Commands.SuggestionRegistry.ASK_SERVER);
|
||||
ProxyCommandNodeHelper.setDefaultSuggestionProvider(Commands.SuggestionRegistry.ASK_SERVER);
|
||||
loadProxyCommands();
|
||||
}
|
||||
|
||||
@@ -105,8 +103,11 @@ public class BungeePacketAnalyzer {
|
||||
channel.pipeline().addAfter(BungeePacketAnalyzer.PIPELINE_NAME, BungeePacketAnalyzer.HANDLER_NAME, new PacketDecoder(player));
|
||||
BungeePacketAnalyzer.INJECTED_PLAYERS.put(player, channel);
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
} catch (Exception exception) {
|
||||
if (!Storage.ConfigSections.Settings.INJECTION_FAILED.SUPPRESS_EXCEPTIONS) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
@@ -115,7 +116,7 @@ public class BungeePacketAnalyzer {
|
||||
}
|
||||
|
||||
public static void uninject(ProxiedPlayer player) {
|
||||
BungeePacketAnalyzer.PLAYER_INPUT_CACHE.remove(player);
|
||||
BungeePacketAnalyzer.PLAYER_INPUT_CACHE.remove(player.getUniqueId());
|
||||
BungeePacketAnalyzer.PLAYER_MODIFIED.remove(player);
|
||||
|
||||
if(BungeePacketAnalyzer.INJECTED_PLAYERS.containsKey(player)) {
|
||||
@@ -132,46 +133,54 @@ public class BungeePacketAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPlayerInput(ProxiedPlayer player, String input) {
|
||||
PLAYER_INPUT_CACHE.putIgnoreIfContains(player.getUniqueId(), input);
|
||||
}
|
||||
|
||||
public static String getPlayerInput(ProxiedPlayer player) {
|
||||
String input = PLAYER_INPUT_CACHE.get(player);
|
||||
PLAYER_INPUT_CACHE.remove(player);
|
||||
String input = PLAYER_INPUT_CACHE.get(player.getUniqueId());
|
||||
PLAYER_INPUT_CACHE.remove(player.getUniqueId());
|
||||
return input;
|
||||
}
|
||||
|
||||
private static void modifyCommands(ProxiedPlayer player, Commands commands) {
|
||||
if (PermissionUtil.hasBypassPermission(player))
|
||||
return;
|
||||
private static void modifyCommands(ProxiedPlayer player, CommandSender sender, Commands commands) {
|
||||
String serverName = sender.getServerName();
|
||||
|
||||
ServerInfo serverInfo = player.getServer().getInfo();
|
||||
String serverName = serverInfo.getName();
|
||||
final boolean ignore = PermissionUtil.hasBypassPermission(sender) || Storage.Blacklist.isDisabledServer(serverName);
|
||||
|
||||
if (Storage.Blacklist.isDisabledServer(serverName))
|
||||
return;
|
||||
|
||||
CommandNodeHelper helper = new CommandNodeHelper<CommandNode>(commands.getRoot());
|
||||
|
||||
Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
|
||||
if (!cache.containsKey(serverName))
|
||||
cache.put(serverName, new CommandsCache());
|
||||
|
||||
CommandsCache commandsCache = cache.get(serverName);
|
||||
ProxyCommandNodeHelper helper = new ProxyCommandNodeHelper<CommandNode>(commands.getRoot());
|
||||
|
||||
List<String> commandsAsString = new ArrayList<>(PROXY_COMMANDS);
|
||||
commandsAsString.addAll(helper.getChildrenNames());
|
||||
|
||||
commandsCache.handleCommands(commandsAsString, serverName);
|
||||
List<String> playerCommands = new ArrayList<>();
|
||||
|
||||
List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, serverName);
|
||||
if (!ignore) {
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
helper.removeIf(str -> !playerCommands.contains(str));
|
||||
final Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
if (!cache.containsKey(serverName)) {
|
||||
cache.put(serverName, new CommandsCache());
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_VERSION.ALWAYS_TAB_COMPLETABLE) {
|
||||
Storage.ConfigSections.Settings.CUSTOM_VERSION.COMMANDS.getLines().forEach(input -> helper.add(input, false));
|
||||
}
|
||||
final CommandsCache commandsCache = cache.get(serverName);
|
||||
commandsCache.handleCommands(commandsAsString, serverName);
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.ALWAYS_TAB_COMPLETABLE) {
|
||||
Storage.ConfigSections.Settings.CUSTOM_PLUGIN.COMMANDS.getLines().forEach(input -> helper.add(input, false));
|
||||
final List<String> tmpPlayerCommands = commandsCache.getPlayerCommands(commandsAsString, sender, groups, serverName);
|
||||
|
||||
if (commands.getRoot().getChildren().size() != 0) {
|
||||
helper.removeIf(str -> !tmpPlayerCommands.contains(str));
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_VERSION.ALWAYS_TAB_COMPLETABLE) {
|
||||
Storage.ConfigSections.Settings.CUSTOM_VERSION.COMMANDS.getLines().forEach(input -> helper.add(input, false));
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.ALWAYS_TAB_COMPLETABLE) {
|
||||
Storage.ConfigSections.Settings.CUSTOM_PLUGIN.COMMANDS.getLines().forEach(input -> helper.add(input, false));
|
||||
}
|
||||
|
||||
playerCommands = tmpPlayerCommands;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Command> command : ProxyServer.getInstance().getPluginManager().getCommands()) {
|
||||
@@ -189,28 +198,46 @@ public class BungeePacketAnalyzer {
|
||||
String commandName = command.getKey();
|
||||
commandName = commandName.startsWith("/") ? commandName.substring(1) : commandName;
|
||||
|
||||
boolean tabablePluginCommand = Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(commandName);
|
||||
boolean tabableVersionCommand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(commandName);
|
||||
if (!ignore) {
|
||||
boolean tabablePluginCommand = Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(commandName);
|
||||
boolean tabableVersionCommand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(commandName);
|
||||
|
||||
if (!tabablePluginCommand && !tabableVersionCommand && !playerCommands.contains(commandName)) {
|
||||
continue;
|
||||
if (!tabablePluginCommand && !tabableVersionCommand && !playerCommands.contains(commandName)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
CommandNode dummy = CommandNodeHelper.createDummyCommandNode(command.getKey());
|
||||
CommandNode dummy = ProxyCommandNodeHelper.createDummyCommandNode(command.getKey());
|
||||
commands.getRoot().addChild(dummy);
|
||||
}
|
||||
|
||||
|
||||
PROXY_COMMANDS.stream().filter(playerCommands::contains).forEach(input -> helper.add(input, true));
|
||||
SubArgsModule.handleCommandNode(player.getUniqueId(), helper);
|
||||
for (String command : PROXY_COMMANDS) {
|
||||
if (ignore || playerCommands.contains(command)) {
|
||||
helper.add(command, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignore) {
|
||||
SubArguments.handleCommandNode(player.getUniqueId(), helper);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendCommandsPacket() {
|
||||
if (!Communicator.get().hasConnectedClients()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
if (player.getPendingConnection().getVersion() < 754)
|
||||
continue;
|
||||
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
|
||||
RootCommandNode root = new RootCommandNode();
|
||||
Commands packet = new Commands(root);
|
||||
|
||||
modifyCommands(player, packet);
|
||||
modifyCommands(player, sender, packet);
|
||||
player.unsafe().sendPacket(packet);
|
||||
}
|
||||
}
|
||||
@@ -218,9 +245,11 @@ public class BungeePacketAnalyzer {
|
||||
private static class PacketDecoder extends MessageToMessageDecoder<PacketWrapper> {
|
||||
|
||||
private final ProxiedPlayer player;
|
||||
private final CommandSender sender;
|
||||
|
||||
private PacketDecoder(ProxiedPlayer player) {
|
||||
this.player = player;
|
||||
this.sender = CommandSenderHandler.from(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -230,37 +259,44 @@ public class BungeePacketAnalyzer {
|
||||
return;
|
||||
}
|
||||
|
||||
if(wrapper.packet instanceof PluginMessage) {
|
||||
if (wrapper.packet instanceof PluginMessage) {
|
||||
PluginMessage pluginMessage = (PluginMessage) wrapper.packet;
|
||||
if(CustomServerBrand.isEnabled() && CustomServerBrand.isBrandTag(pluginMessage.getTag()))
|
||||
return;
|
||||
|
||||
} else if (wrapper.packet instanceof Commands) {
|
||||
Commands response = (Commands) wrapper.packet;
|
||||
modifyCommands(player, response);
|
||||
modifyCommands(player, sender, response);
|
||||
|
||||
player.unsafe().sendPacket(response);
|
||||
return;
|
||||
|
||||
/*
|
||||
} else if (wrapper.packet instanceof TabCompleteResponse) {
|
||||
TabCompleteResponse response = (TabCompleteResponse) wrapper.packet;
|
||||
String serverName = player.getServer().getInfo().getName();
|
||||
|
||||
System.out.println("damn");
|
||||
|
||||
if (!Storage.Blacklist.isDisabledServer(serverName) && player.getPendingConnection().getVersion() < 754) {
|
||||
if (!PermissionUtil.hasBypassPermission(player)) {
|
||||
|
||||
ClientInfo clientInfo = Communicator.getClientByName(player.getServer().getInfo().getName());
|
||||
if (clientInfo == null || !PLAYER_INPUT_CACHE.containsKey(player))
|
||||
System.out.println("Further!");
|
||||
System.out.println("Got: " + PLAYER_INPUT_CACHE.get(player.getUniqueId()));
|
||||
|
||||
if (!PLAYER_INPUT_CACHE.contains(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
boolean cancelsBeforeHand = false;
|
||||
|
||||
String rawPlayerInput = getPlayerInput(player);
|
||||
String rawPlayerInput = PLAYER_INPUT_CACHE.get(player.getUniqueId());
|
||||
int spaces = rawPlayerInput.contains(" ") ? rawPlayerInput.split(" ").length : 0;
|
||||
|
||||
String playerInput = StringUtils.getFirstArg(rawPlayerInput),
|
||||
server = player.getServer().getInfo().getName();
|
||||
|
||||
System.out.println("NETTY -> " + playerInput);
|
||||
|
||||
if (!playerInput.equals("/")) {
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(player, StringUtils.replaceFirst(playerInput, "/", ""), server);
|
||||
|
||||
@@ -318,7 +354,7 @@ public class BungeePacketAnalyzer {
|
||||
player.unsafe().sendPacket(new TabCompleteResponse(response.getCommands()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
list.add(wrapper);
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
|
||||
@@ -19,12 +21,18 @@ import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.plugin.listeners.velocity.VelocityBlockCommandListener;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.node.ProxyCommandNodeHelper;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -34,6 +42,31 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class VelocityPacketAnalyzer {
|
||||
|
||||
private static boolean FAILED = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
final String name = "minecraft:ask_server";
|
||||
|
||||
final Object availableCommandsPacket = AvailableCommandsPacket.class.newInstance();
|
||||
final Class<?> packetInstanceObjClass = availableCommandsPacket.getClass();
|
||||
|
||||
for (Class<?> clazz : packetInstanceObjClass.getClasses()) {
|
||||
if (clazz.getSimpleName().equals("ProtocolSuggestionProvider")) {
|
||||
final Object suggestionProviderObj = clazz.getConstructor(String.class).newInstance(name);
|
||||
final SuggestionProvider<?> suggestionProvider = (SuggestionProvider<?>) suggestionProviderObj;
|
||||
|
||||
ProxyCommandNodeHelper.setDefaultSuggestionProvider(suggestionProvider);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
FAILED = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final ConcurrentHashMap<Player, Channel> INJECTED_PLAYERS = new ConcurrentHashMap<>();
|
||||
|
||||
private static final String PIPELINE_NAME = "pat-velocity-handler", HANDLER_NAME = "handler";
|
||||
@@ -85,8 +118,11 @@ public class VelocityPacketAnalyzer {
|
||||
Logger.warning("Failed to find 'handler' inside player pipeline! (name=" + player.getUsername() + ", uuid=" + player.getUniqueId() + ", version=" + player.getProtocolVersion() + ", brand=" + player.getClientBrand() + " )");
|
||||
return false;
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
} catch (Exception exception) {
|
||||
if (!Storage.ConfigSections.Settings.INJECTION_FAILED.SUPPRESS_EXCEPTIONS) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -118,12 +154,67 @@ public class VelocityPacketAnalyzer {
|
||||
PLAYER_INPUT_CACHE.put(player, text.toLowerCase());
|
||||
}
|
||||
|
||||
private static void modifyCommands(Player player, CommandSender sender, AvailableCommandsPacket commands) {
|
||||
|
||||
if (commands.getRootNode().getChildren().size() == 1
|
||||
&& player.getProtocolVersion().getProtocol() > 340
|
||||
&& commands.getRootNode().getChild("args") != null
|
||||
&& commands.getRootNode().getChild("args").getChildren().isEmpty()) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String serverName = sender.getServerName();
|
||||
|
||||
final boolean ignore = PermissionUtil.hasBypassPermission(sender) || Storage.Blacklist.isDisabledServer(serverName);
|
||||
final ProxyCommandNodeHelper<CommandSource> helper = new ProxyCommandNodeHelper<>(commands.getRootNode());
|
||||
|
||||
final List<String> commandsAsString = new ArrayList<>();
|
||||
commandsAsString.addAll(helper.getChildrenNames());
|
||||
|
||||
if (ignore) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
final Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
if (!cache.containsKey(serverName)) {
|
||||
cache.put(serverName, new CommandsCache());
|
||||
}
|
||||
|
||||
final CommandsCache commandsCache = cache.get(serverName);
|
||||
commandsCache.handleCommands(commandsAsString, serverName);
|
||||
|
||||
final List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, sender, groups, serverName);
|
||||
helper.removeIf(str -> {
|
||||
if (str.equals("args")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !playerCommands.contains(str);
|
||||
});
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_VERSION.ALWAYS_TAB_COMPLETABLE) {
|
||||
Storage.ConfigSections.Settings.CUSTOM_VERSION.COMMANDS.getLines().forEach(input -> helper.add(input, false));
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.ALWAYS_TAB_COMPLETABLE) {
|
||||
Storage.ConfigSections.Settings.CUSTOM_PLUGIN.COMMANDS.getLines().forEach(input -> helper.add(input, false));
|
||||
}
|
||||
|
||||
SubArguments.handleCommandNode(player.getUniqueId(), helper);
|
||||
}
|
||||
|
||||
private static class PacketDecoder extends ChannelDuplexHandler {
|
||||
|
||||
private final Player player;
|
||||
private final CommandSender sender;
|
||||
|
||||
private PacketDecoder(Player player) {
|
||||
this.player = player;
|
||||
this.sender = CommandSenderHandler.from(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,15 +244,12 @@ public class VelocityPacketAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
if (packet instanceof UnsignedPlayerCommandPacket) {
|
||||
|
||||
UnsignedPlayerCommandPacket unsignedPlayerCommandPacket = (UnsignedPlayerCommandPacket) packet;
|
||||
if (packet instanceof UnsignedPlayerCommandPacket unsignedPlayerCommandPacket) {
|
||||
if (!VelocityBlockCommandListener.handleCommand(player, unsignedPlayerCommandPacket.getCommand()).getResult().isAllowed())
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet instanceof TabCompleteRequestPacket) {
|
||||
TabCompleteRequestPacket request = (TabCompleteRequestPacket) msg;
|
||||
if (packet instanceof TabCompleteRequestPacket request) {
|
||||
if (request.getCommand() != null) {
|
||||
|
||||
if (Storage.ConfigSections.Settings.PATCH_EXPLOITS.isMalicious(request.getCommand())) {
|
||||
@@ -184,15 +272,14 @@ public class VelocityPacketAnalyzer {
|
||||
|
||||
MinecraftPacket packet = (MinecraftPacket) msg;
|
||||
|
||||
if (packet instanceof PluginMessagePacket) {
|
||||
PluginMessagePacket pluginMessagePacket = (PluginMessagePacket) packet;
|
||||
if (packet instanceof PluginMessagePacket pluginMessagePacket) {
|
||||
if(CustomServerBrand.isEnabled() && CustomServerBrand.isBrandTag(pluginMessagePacket.getChannel()) && !player.getCurrentServer().isPresent()) {
|
||||
PacketUtils.BrandManipulate brandManipulatePacket = CustomServerBrand.createBrandPacket(player);
|
||||
super.write(ctx, new PluginMessagePacket(pluginMessagePacket.getChannel(), brandManipulatePacket.getByteBuf()), promise);
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (packet instanceof TabCompleteResponsePacket) {
|
||||
} else if (packet instanceof TabCompleteResponsePacket response) {
|
||||
|
||||
String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
|
||||
|
||||
@@ -201,23 +288,23 @@ public class VelocityPacketAnalyzer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player) && player.getCurrentServer().isPresent()) {
|
||||
TabCompleteResponsePacket response = (TabCompleteResponsePacket) packet;
|
||||
if (!PermissionUtil.hasBypassPermission(sender) && player.getCurrentServer().isPresent()) {
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
boolean cancelsBeforeHand = false;
|
||||
String playerInput = getPlayerInput(player), rawPlayerInput = playerInput, server = player.getCurrentServer().get().getServerInfo().getName();
|
||||
int spaces = 0;
|
||||
|
||||
if(playerInput.contains(" ")) {
|
||||
if (playerInput.contains(" ")) {
|
||||
String[] split = playerInput.split(" ");
|
||||
spaces = split.length;
|
||||
if(spaces > 0) playerInput = split[0];
|
||||
if (spaces > 0) playerInput = split[0];
|
||||
}
|
||||
|
||||
if(!playerInput.equals("/")) {
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(player, StringUtils.replaceFirst(playerInput, "/", ""), server);
|
||||
if (!playerInput.equals("/")) {
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(sender, groups, StringUtils.replaceFirst(playerInput, "/", ""), server);
|
||||
|
||||
if(!cancelsBeforeHand)
|
||||
if (!cancelsBeforeHand)
|
||||
cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", "")) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", ""));
|
||||
}
|
||||
|
||||
@@ -237,7 +324,7 @@ public class VelocityPacketAnalyzer {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, command, player.getCurrentServer().get().getServerInfo().getName());
|
||||
return !Storage.Blacklist.canPlayerAccessTab(sender, groups, command, player.getCurrentServer().get().getServerInfo().getName());
|
||||
});
|
||||
} else {
|
||||
if (cancelsBeforeHand) return;
|
||||
@@ -258,18 +345,31 @@ public class VelocityPacketAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
} else if (packet instanceof AvailableCommandsPacket) {
|
||||
} else if (packet instanceof AvailableCommandsPacket commands) {
|
||||
|
||||
if (player.getCurrentServer().isPresent()) {
|
||||
|
||||
if (!FAILED) {
|
||||
modifyCommands(player, sender, commands);
|
||||
super.write(ctx, msg, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player)) {
|
||||
super.write(ctx, msg, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
final String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player) && player.getCurrentServer().isPresent()) {
|
||||
|
||||
String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
|
||||
|
||||
if (Storage.Blacklist.isDisabledServer(serverName)) {
|
||||
super.write(ctx, msg, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
AvailableCommandsPacket commands = (AvailableCommandsPacket) packet;
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
if(!commands.getRootNode().getChildren().isEmpty()) {
|
||||
Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
@@ -286,7 +386,7 @@ public class VelocityPacketAnalyzer {
|
||||
if (PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
final boolean newer = player.getProtocolVersion().getProtocol() > 340;
|
||||
final List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, serverName);
|
||||
final List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, sender, groups, serverName);
|
||||
|
||||
if (commands.getRootNode().getChildren().size() == 1 && newer
|
||||
&& commands.getRootNode().getChild("args") != null
|
||||
@@ -296,16 +396,16 @@ public class VelocityPacketAnalyzer {
|
||||
return;
|
||||
}
|
||||
|
||||
commands.getRootNode().getChildren().removeIf(command -> {
|
||||
commands.getRootNode().getChildren().removeIf(command -> {
|
||||
if (command == null || command.getName() == null)
|
||||
return true;
|
||||
|
||||
if (command.getName().equals("args"))
|
||||
return false;
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(command.getName()) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(command.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(command.getName()) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(command.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !playerCommands.contains(command.getName());
|
||||
});
|
||||
|
||||
@@ -11,9 +11,11 @@ import de.rayzs.pat.api.storage.config.messages.*;
|
||||
import de.rayzs.pat.api.storage.config.settings.*;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.BukkitAntiTabListener;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.permission.PermissionPlugin;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
@@ -58,12 +60,12 @@ public class Storage {
|
||||
|
||||
public static final List<UUID> NOTIFY_PLAYERS = new ArrayList<>();
|
||||
|
||||
public static String TOKEN = "", SERVER_NAME = null, CURRENT_VERSION = "", NEWER_VERSION = "";
|
||||
public static String TOKEN = "", CENSORED_TOKEN = "", SERVER_NAME = null, CURRENT_VERSION = "", NEWER_VERSION = "";
|
||||
public static boolean OUTDATED = false, SEND_CONSOLE_NOTIFICATION = true;
|
||||
public static Object PLUGIN_OBJECT;
|
||||
public static boolean USE_PLACEHOLDERAPI = false, USE_PAPIPROXYBRIDGE = false, USE_VIAVERSION = false, USE_VELOCITY = false, USE_SIMPLECLOUD;
|
||||
public static long LAST_SYNC = System.currentTimeMillis();
|
||||
public static boolean USE_PLACEHOLDERAPI = false, USE_PAPIPROXYBRIDGE = false, USE_VIAVERSION = false;
|
||||
|
||||
private final static ExpireCache<UUID, String> TEMP_PLAYER_SERVER_CACHE = new ExpireCache<>(1, TimeUnit.SECONDS);
|
||||
private static PermissionPlugin PERMISSION_PLUGIN = PermissionPlugin.NONE;
|
||||
|
||||
public static void initialize(PluginLoader loader, String currentVersion) {
|
||||
@@ -79,13 +81,14 @@ public class Storage {
|
||||
PERMISSION_PLUGIN = permissionPlugin;
|
||||
}
|
||||
|
||||
|
||||
public static void broadcastPermissionsPluginNotice() {
|
||||
if (Storage.getPermissionPlugin() != PermissionPlugin.NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.warning("No known permissions plugin found, so some features may be disabled.");
|
||||
Logger.warning("Read more about it here: http://rayzs.de/products/proantitab/nkppf");
|
||||
Logger.warning("Read more about it here: https://rayzs.de/products/proantitab/nkppf");
|
||||
}
|
||||
|
||||
public static PermissionPlugin getPermissionPlugin() {
|
||||
@@ -97,9 +100,9 @@ public class Storage {
|
||||
loadToken();
|
||||
|
||||
if (TOKEN != null && !TOKEN.isEmpty()) {
|
||||
int tokenLength = TOKEN.length(), cutIndex = Math.max(1, tokenLength - 3);
|
||||
String censoredTokenDisplay = "*".repeat(cutIndex) + TOKEN.substring(cutIndex);
|
||||
Logger.info("Token found! (" + censoredTokenDisplay + ")");
|
||||
int tokenLength = TOKEN.length(), cutIndex = Math.max(1, tokenLength - 2);
|
||||
CENSORED_TOKEN = TOKEN.charAt(0) + "*".repeat(cutIndex) + TOKEN.substring(cutIndex);
|
||||
Logger.info("Token found! (" + CENSORED_TOKEN + ")");
|
||||
}
|
||||
|
||||
if (loadBlacklist) Blacklist.loadAll();
|
||||
@@ -108,6 +111,7 @@ public class Storage {
|
||||
}
|
||||
|
||||
public static void loadToken() {
|
||||
Files.TOKEN.reload();
|
||||
|
||||
boolean invalidEnv = false;
|
||||
|
||||
@@ -175,14 +179,18 @@ public class Storage {
|
||||
GroupManager.initialize();
|
||||
|
||||
if (!proxy) {
|
||||
BackendUpdater.stop();
|
||||
BackendUpdater.start();
|
||||
Communicator.get().reload();
|
||||
BackendUpdater.restart();
|
||||
}
|
||||
|
||||
if (!backend) {
|
||||
Storage.handleChange();
|
||||
}
|
||||
|
||||
if (proxy) {
|
||||
Communicator.Proxy2Backend.sendDataSync();
|
||||
}
|
||||
|
||||
ConfigUpdater.broadcastMissingParts();
|
||||
Storage.getLoader().handleReload();
|
||||
}
|
||||
@@ -216,11 +224,11 @@ public class Storage {
|
||||
|
||||
associatedServers.forEach(s -> {
|
||||
List<UUID> playerIds = Storage.getLoader().getPlayerIdsByServer(s);
|
||||
List<String> commands = new ArrayList<>(SubArgsModule.getServerCommands(s));
|
||||
List<String> commands = new ArrayList<>(SubArguments.getServerCommands(s));
|
||||
|
||||
playerIds.forEach(playerId -> {
|
||||
List<String> playerCommands = new ArrayList<>(commands);
|
||||
playerCommands.addAll(SubArgsModule.getGroupCommands(playerId, s));
|
||||
playerCommands.addAll(SubArguments.getGroupCommands(playerId, s));
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(playerId, playerCommands, true);
|
||||
});
|
||||
@@ -236,8 +244,8 @@ public class Storage {
|
||||
List<UUID> playerIds = Storage.getLoader().getPlayerIds();
|
||||
|
||||
playerIds.forEach(playerId -> {
|
||||
List<String> playerCommands = new ArrayList<>(SubArgsModule.getServerCommands(playerId));
|
||||
playerCommands.addAll(SubArgsModule.getGroupCommands(playerId));
|
||||
List<String> playerCommands = new ArrayList<>(SubArguments.getServerCommands(playerId));
|
||||
playerCommands.addAll(SubArguments.getGroupCommands(playerId));
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(playerId, playerCommands, false);
|
||||
});
|
||||
@@ -246,28 +254,27 @@ public class Storage {
|
||||
}
|
||||
|
||||
GroupManager.clearServerGroupBlacklists();
|
||||
Communicator.syncData();
|
||||
|
||||
Storage.getLoader().updateCommandCache();
|
||||
Communicator.sendPermissionReset();
|
||||
|
||||
if (!Reflection.isVelocityServer()) {
|
||||
BungeePacketAnalyzer.sendCommandsPacket();
|
||||
}
|
||||
|
||||
Communicator.Proxy2Backend.sendUpdateCommand();
|
||||
return;
|
||||
}
|
||||
|
||||
getLoader().handleReload();
|
||||
PermissionUtil.reloadPermissions();
|
||||
|
||||
if (Reflection.getMinor() < 13) {
|
||||
if (Reflection.isBefore(1, 13)) {
|
||||
final List<UUID> playerIds = Storage.getLoader().getPlayerIds();
|
||||
final List<String> commands = new ArrayList<>(Blacklist.BLACKLIST.getCommands());
|
||||
|
||||
playerIds.forEach(playerId -> {
|
||||
List<String> playerCommands = new ArrayList<>(commands);
|
||||
playerCommands.addAll(SubArgsModule.getGroupCommands(playerId));
|
||||
playerCommands.addAll(SubArguments.getGroupCommands(playerId));
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(playerId, playerCommands, true);
|
||||
});
|
||||
@@ -276,10 +283,22 @@ public class Storage {
|
||||
}
|
||||
}
|
||||
|
||||
public static void tempCachePlayerToServer(UUID playerId, String server) {
|
||||
TEMP_PLAYER_SERVER_CACHE.put(playerId, server);
|
||||
}
|
||||
|
||||
public static void getTempCachedPlayerToServer(UUID playerId, String server) {
|
||||
TEMP_PLAYER_SERVER_CACHE.put(playerId, server);
|
||||
}
|
||||
|
||||
public static String getCachedPlayerServername(UUID playerId) {
|
||||
return TEMP_PLAYER_SERVER_CACHE.get(playerId);
|
||||
}
|
||||
|
||||
// Quickly updates all player subarguments.
|
||||
public static void quickSubArgumentUpdate(UUID uuid) {
|
||||
List<String> playerCommands = new ArrayList<>(SubArgsModule.getServerCommands(uuid));
|
||||
playerCommands.addAll(SubArgsModule.getGroupCommands(uuid));
|
||||
List<String> playerCommands = new ArrayList<>(SubArguments.getServerCommands(uuid));
|
||||
playerCommands.addAll(SubArguments.getGroupCommands(uuid));
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(uuid, playerCommands, false);
|
||||
}
|
||||
@@ -340,15 +359,18 @@ public class Storage {
|
||||
|
||||
public static class Settings {
|
||||
|
||||
public static AllowGroupOverrulingSection ALLOW_GROUP_OVERRULING = new AllowGroupOverrulingSection();
|
||||
public static AutoLowercaseCommandsSection AUTO_LOWERCASE_COMMANDS = new AutoLowercaseCommandsSection();
|
||||
public static BlockNamespaceCommandsSection BLOCK_NAMESPACE_COMMANDS = new BlockNamespaceCommandsSection();
|
||||
public static HandleThroughProxySection HANDLE_THROUGH_PROXY = new HandleThroughProxySection();
|
||||
public static InjectionFailedSection INJECTION_FAILED = new InjectionFailedSection();
|
||||
public static PatchExploitSection PATCH_EXPLOITS = new PatchExploitSection();
|
||||
public static CustomBrandSection CUSTOM_BRAND = new CustomBrandSection();
|
||||
public static CancelCommandSection CANCEL_COMMAND = new CancelCommandSection();
|
||||
public static CustomPluginsSection CUSTOM_PLUGIN = new CustomPluginsSection();
|
||||
public static CustomVersionSection CUSTOM_VERSION = new CustomVersionSection();
|
||||
public static DisableSyncSection DISABLE_SYNC = new DisableSyncSection();
|
||||
public static ForwardConsoleNotificationAlertsSection FORWARD_CONSOLE_NOTIFICATIONS = new ForwardConsoleNotificationAlertsSection();
|
||||
public static CustomProtocolPingSection CUSTOM_PROTOCOL_PING = new CustomProtocolPingSection();
|
||||
public static CustomUnknownCommandSection CUSTOM_UNKNOWN_COMMAND = new CustomUnknownCommandSection();
|
||||
public static TurnBlacklistToWhitelistSection TURN_BLACKLIST_TO_WHITELIST = new TurnBlacklistToWhitelistSection();
|
||||
@@ -555,41 +577,62 @@ public class Storage {
|
||||
return IGNORED_SERVERS.isListed(server);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccess(Object player, String command, BlockType type) {
|
||||
return canPlayerAccess(player, command, type, null);
|
||||
public static boolean canPlayerAccess(CommandSender sender, List<Group> groups, String command, BlockType type) {
|
||||
return canPlayerAccess(sender, groups, command, type, null);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccessChat(Object player, String command) {
|
||||
return canPlayerAccess(player, command, BlockType.CHAT, null);
|
||||
public static boolean canPlayerAccessChat(CommandSender sender, List<Group> groups, String command) {
|
||||
return canPlayerAccess(sender, groups, command, BlockType.CHAT, null);
|
||||
}
|
||||
|
||||
|
||||
public static boolean canPlayerAccessChat(Object player, String command, String server) {
|
||||
return canPlayerAccess(player, command, BlockType.CHAT, server);
|
||||
public static boolean canPlayerAccessChat(CommandSender sender, List<Group> groups, String command, String server) {
|
||||
return canPlayerAccess(sender, groups, command, BlockType.CHAT, server);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccessTab(Object player, String command) {
|
||||
return canPlayerAccess(player, command, BlockType.TAB, null);
|
||||
public static boolean canPlayerAccessTab(CommandSender sender, List<Group> groups, String command) {
|
||||
return canPlayerAccess(sender, groups, command, BlockType.TAB, null);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccessTab(Object player, String command, String server) {
|
||||
return canPlayerAccess(player, command, BlockType.TAB, server);
|
||||
public static boolean canPlayerAccessTab(CommandSender sender, List<Group> groups, String command, String server) {
|
||||
return canPlayerAccess(sender, groups, command, BlockType.TAB, server);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccess(Object player, String command, BlockType type, String server) {
|
||||
boolean blocked = isBlocked(command, type, server);
|
||||
public static boolean canPlayerAccess(CommandSender sender, List<Group> groups, String command, BlockType type, String server) {
|
||||
final boolean allowGroupOverruling = ConfigSections.Settings.ALLOW_GROUP_OVERRULING.ENABLED;
|
||||
final boolean blocked = isBlocked(command, type, server);
|
||||
|
||||
if (allowGroupOverruling) {
|
||||
GroupManager.AccessResult groupResult = GroupManager.canAccessCommand(groups, command, type, server);
|
||||
if (groupResult == GroupManager.AccessResult.NEGATED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!blocked) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Storage.getPermissionPlugin() != PermissionPlugin.NONE) {
|
||||
if (PermissionUtil.hasBypassPermission(sender, command)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return groupResult.asBoolean();
|
||||
}
|
||||
|
||||
|
||||
if (!blocked) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Storage.getPermissionPlugin() != PermissionPlugin.NONE) {
|
||||
if (PermissionUtil.hasBypassPermission(player, command)) {
|
||||
if (PermissionUtil.hasBypassPermission(sender, command)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return GroupManager.canAccessCommand(player, command, type, server);
|
||||
return GroupManager.canAccessCommand(groups, command, type, server).asBoolean();
|
||||
}
|
||||
|
||||
public static boolean isBlockedChat(String command) {
|
||||
@@ -617,34 +660,35 @@ public class Storage {
|
||||
BlockType negation = BlockType.NEGATE;
|
||||
String negatedCommand = negation + command;
|
||||
|
||||
boolean listed = isListed(command, type, server),
|
||||
boolean all = isListed("*", type, server),
|
||||
listed = isListed(command, type, server),
|
||||
negatedListed = isListed(negatedCommand, type, server),
|
||||
turn = ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
|
||||
if (all) {
|
||||
// Only listens to negated commands
|
||||
if (negatedListed) {
|
||||
return turn;
|
||||
}
|
||||
|
||||
if (!turn && negatedListed) {
|
||||
listed = !listed;
|
||||
return !turn;
|
||||
}
|
||||
|
||||
if (turn) {
|
||||
return !listed;
|
||||
} else {
|
||||
return listed;
|
||||
}
|
||||
return turn != listed;
|
||||
|
||||
}
|
||||
|
||||
private static boolean isListed(String unmodifiedCommand, BlockType type, String server) {
|
||||
if (server != null && isDisabledServer(server))
|
||||
if (server != null && isDisabledServer(server)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
boolean listed = false;
|
||||
|
||||
String command = type.toString() + unmodifiedCommand;
|
||||
|
||||
if (server == null || !isIgnoredServer(server)) {
|
||||
listed = BLACKLIST.isListed(command, false/*!turn*/);
|
||||
listed = BLACKLIST.isListed(command, false);
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
@@ -661,11 +705,11 @@ public class Storage {
|
||||
blacklists.add(BLACKLIST);
|
||||
|
||||
for (GeneralBlacklist blacklist : blacklists) {
|
||||
if (listed/* && turn*/) {
|
||||
if (listed) {
|
||||
break;
|
||||
}
|
||||
|
||||
listed = blacklist.isListed(command, false/*turn*/);
|
||||
listed = blacklist.isListed(command, false);
|
||||
}
|
||||
|
||||
if (!listed && type != BlockType.BOTH) {
|
||||
@@ -677,6 +721,19 @@ public class Storage {
|
||||
|
||||
public static class BlockTypeFetcher {
|
||||
|
||||
public static boolean isNegated(String command) {
|
||||
if (command.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean negated = command.charAt(0) == '!';
|
||||
|
||||
if (!negated && command.length() > 5)
|
||||
negated = command.charAt(5) == '!';
|
||||
|
||||
return negated;
|
||||
}
|
||||
|
||||
public static BlockType getType(String command) {
|
||||
for (BlockType blockType : BLOCK_TYPES) {
|
||||
if (!command.startsWith(blockType.toString()))
|
||||
@@ -700,6 +757,17 @@ public class Storage {
|
||||
return command.substring(type.toString().length());
|
||||
}
|
||||
|
||||
// Remove all BlockType elements from String
|
||||
public static String cleanse(String command) {
|
||||
BlockType type = getType(command);
|
||||
|
||||
if (type == null || type == BlockType.BOTH) {
|
||||
return command;
|
||||
}
|
||||
|
||||
return modify(command, type);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class ExtractSection extends ConfigStorage {
|
||||
return;
|
||||
}
|
||||
|
||||
USAGE = new ConfigSectionHelper<String>(this, "usage", "&7Usage: &f/pat extract [plugin] <use-colon> &7or &f<group> <use-colon>").getOrSet();
|
||||
USAGE = new ConfigSectionHelper<String>(this, "usage", "&7Usage: &f/pat extract (plugin) <option> &7or &f(group) <option>").getOrSet();
|
||||
PLUGIN_NOT_FOUND = new ConfigSectionHelper<String>(this, "plugin-not-found", "&cPlugin %plugin% not found!").getOrSet();
|
||||
SUCCESS = new ConfigSectionHelper<String>(this, "success", "&aSuccessfully extracted &e%amount% &anew commands from %plugin%!").getOrSet();
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package de.rayzs.pat.api.storage.config.messages;
|
||||
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.configuration.helper.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class InfoSection extends ConfigStorage {
|
||||
|
||||
public String VERSION_OUTDATED, VERSION_UPDATED, SYNC_TIME, SYNC_DISABLED;
|
||||
public String VERSION_OUTDATED, VERSION_UPDATED, SYNC_TIME, SYNC_DISABLED, SYNC_WAITING;
|
||||
public MultipleMessagesHelper MESSAGE;
|
||||
|
||||
public InfoSection() {
|
||||
@@ -20,6 +21,11 @@ public class InfoSection extends ConfigStorage {
|
||||
VERSION_UPDATED = new ConfigSectionHelper<String>(this, "version.updated", "&aLatest version").getOrSet();
|
||||
VERSION_OUTDATED = new ConfigSectionHelper<String>(this, "version.outdated", "&cOutdated (%newest_version%)").getOrSet();
|
||||
SYNC_TIME = new ConfigSectionHelper<String>(this, "proxy-sync.time", "&e%time%").getOrSet();
|
||||
|
||||
if (!Reflection.isProxyServer()) {
|
||||
SYNC_WAITING = new ConfigSectionHelper<String>(this, "proxy-sync.waiting", "&cWaiting to establish connection...").getOrSet();
|
||||
}
|
||||
|
||||
SYNC_DISABLED = new ConfigSectionHelper<String>(this, "proxy-sync.disabled", "&cDisabled").getOrSet();
|
||||
|
||||
MESSAGE = new MultipleMessagesHelper(this, "message",
|
||||
@@ -28,6 +34,7 @@ public class InfoSection extends ConfigStorage {
|
||||
, "&7 Version: &e%current_version%"
|
||||
, "&7 Status: %version_status%"
|
||||
, "&7 Last sync with proxy: &e%sync_time%"
|
||||
, "&7 Last received alive packet: %last_alive_response%"
|
||||
, "&7 Proxy sync-token: &e%token%"
|
||||
, "&7 Proxy-received server name: &e%sync_server_name%"
|
||||
)
|
||||
|
||||
@@ -18,12 +18,17 @@ public class StatsSection extends ConfigStorage {
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
if(!Reflection.isProxyServer()) return;
|
||||
|
||||
if (!Reflection.isProxyServer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
NO_SERVER = new ConfigSectionHelper<String>(this, "no-server", "&cNone!").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "message.splitter", "&7, ").getOrSet();
|
||||
SERVER = new ConfigSectionHelper<String>(this, "message.server", "&f%servername% &8(%updated%)").getOrSet();
|
||||
SERVER = new ConfigSectionHelper<String>(this, "message.server", "&f%servername% &8(&a%last_alive_response% &8/ &2%updated%&8)").getOrSet();
|
||||
STATISTIC = new MultipleMessagesHelper(this, "message.statistic", Arrays.asList(
|
||||
"&7Last sync sent to &f%server_count% &7servers. &8&o(%last_sync_time% ago)",
|
||||
"&7Format: &eserver (last alive packet / last sync packet)",
|
||||
"&7Last sync sent to &f%server_count% &7server(s) &e%last_sync_time% &7ago:",
|
||||
"&7Sent to servers: &f%servers%"
|
||||
));
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package de.rayzs.pat.api.storage.config.settings;
|
||||
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
|
||||
public class AllowGroupOverrulingSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED;
|
||||
|
||||
public AllowGroupOverrulingSection() {
|
||||
super("allow-group-overruling");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, null, false).getOrSet();
|
||||
}
|
||||
}
|
||||
-8
@@ -4,7 +4,6 @@ import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
|
||||
public class AutoLowercaseCommandsSection extends ConfigStorage {
|
||||
|
||||
@@ -18,9 +17,6 @@ public class AutoLowercaseCommandsSection extends ConfigStorage {
|
||||
public void load() {
|
||||
super.load();
|
||||
|
||||
if (Reflection.isProxyServer())
|
||||
return;
|
||||
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
|
||||
}
|
||||
|
||||
@@ -29,8 +25,4 @@ public class AutoLowercaseCommandsSection extends ConfigStorage {
|
||||
|
||||
return !StringUtils.isLowercased(command);
|
||||
}
|
||||
|
||||
public boolean doesBypass(Object targetObj) {
|
||||
return !ENABLED || PermissionUtil.hasPermission(targetObj, "auto-lowercase");
|
||||
}
|
||||
}
|
||||
+13
-7
@@ -1,14 +1,13 @@
|
||||
package de.rayzs.pat.api.storage.config.settings;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
public class BlockNamespaceCommandsSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED;
|
||||
public boolean ENABLED, ALWAYS_BLOCK_COMMAND;
|
||||
|
||||
public BlockNamespaceCommandsSection() {
|
||||
super("block-namespace-commands");
|
||||
@@ -18,15 +17,22 @@ public class BlockNamespaceCommandsSection extends ConfigStorage {
|
||||
public void load() {
|
||||
super.load();
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
|
||||
ALWAYS_BLOCK_COMMAND = new ConfigSectionHelper<Boolean>(this, "always-block-command", true).getOrSet();
|
||||
}
|
||||
|
||||
public boolean doesAlwaysBlock(String command) {
|
||||
return ALWAYS_BLOCK_COMMAND && isCommand(command);
|
||||
}
|
||||
|
||||
public boolean isCommand(String command) {
|
||||
if(!ENABLED || Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) return false;
|
||||
if (!ENABLED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return StringUtils.getFirstArg(command).contains(":");
|
||||
}
|
||||
|
||||
public boolean doesBypass(Object targetObj) {
|
||||
|
||||
return !ENABLED || PermissionUtil.hasPermission(targetObj, "namespace");
|
||||
public boolean doesBypass(CommandSender sender) {
|
||||
return !ENABLED || sender.hasPermission("namespace");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class CustomProtocolPingSection extends ConfigStorage {
|
||||
public void load() {
|
||||
super.load();
|
||||
|
||||
if (!Reflection.isProxyServer() && (!Reflection.isPaper() || Reflection.getMinor() < 12))
|
||||
if (!Reflection.isProxyServer() && (!Reflection.isPaper() || Reflection.isBefore(1, 12)))
|
||||
return;
|
||||
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package de.rayzs.pat.api.storage.config.settings;
|
||||
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
|
||||
public class ForwardConsoleNotificationAlertsSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED;
|
||||
|
||||
public ForwardConsoleNotificationAlertsSection() {
|
||||
super("forward-console-notification-alerts");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
|
||||
if(!Reflection.isProxyServer()) return;
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, null, false).getOrSet();
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -6,7 +6,7 @@ import de.rayzs.pat.utils.Reflection;
|
||||
|
||||
public class HandleThroughProxySection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED;
|
||||
public boolean ENABLED, ALLOW_P2B_ACTIONS;
|
||||
|
||||
public boolean LOAD_FROM_ENV;
|
||||
public String ENV_NAME;
|
||||
@@ -20,11 +20,13 @@ public class HandleThroughProxySection extends ConfigStorage {
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
if(Reflection.isProxyServer()) return;
|
||||
if (Reflection.isProxyServer()) return;
|
||||
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", false).getOrSet();
|
||||
TOKEN = new ConfigSectionHelper<String>(this, "token", "insert-token-of-proxy-here").getOrSet();
|
||||
|
||||
ALLOW_P2B_ACTIONS = new ConfigSectionHelper<Boolean>(this, "allow-p2b-actions", false).getOrSet();
|
||||
|
||||
LOAD_FROM_ENV = new ConfigSectionHelper<Boolean>(this, "load-from-env.enabled", false).getOrSet();
|
||||
ENV_NAME = new ConfigSectionHelper<String>(this, "load-from-env.name", "PAT_TOKEN").getOrSet();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package de.rayzs.pat.api.storage.config.settings;
|
||||
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
|
||||
public class InjectionFailedSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED, SUPPRESS_EXCEPTIONS;
|
||||
public String KICK_MESSAGE, CONSOLE_MESSAGE;
|
||||
|
||||
public InjectionFailedSection() {
|
||||
super("injection-failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "kick-on-failure", true).getOrSet();
|
||||
SUPPRESS_EXCEPTIONS = new ConfigSectionHelper<Boolean>(this, "suppress-exceptions", false).getOrSet();
|
||||
KICK_MESSAGE = new ConfigSectionHelper<String>(this, "kick-message", "&cInjection process failed! Please reconnect.").getOrSet();
|
||||
CONSOLE_MESSAGE = new ConfigSectionHelper<String>(this, "console-message", "&cInjection process failed! (%player%)").getOrSet();
|
||||
}
|
||||
}
|
||||
-3
@@ -6,7 +6,6 @@ import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
|
||||
public class UpdateGroupsPerServerSection extends ConfigStorage {
|
||||
|
||||
// Disabled for now
|
||||
public boolean ENABLED = false;
|
||||
|
||||
public UpdateGroupsPerServerSection() {
|
||||
@@ -17,11 +16,9 @@ public class UpdateGroupsPerServerSection extends ConfigStorage {
|
||||
public void load() {
|
||||
super.load();
|
||||
|
||||
/*
|
||||
if (!Reflection.isProxyServer())
|
||||
return;
|
||||
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, null, false).getOrSet();
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -9,27 +9,31 @@ import java.util.*;
|
||||
public class BlacklistStorage extends StorageTemplate implements Serializable {
|
||||
|
||||
private List<String> commands = new ArrayList<>();
|
||||
private List<String> hiddenCommands = new ArrayList<>();
|
||||
|
||||
public BlacklistStorage(String navigatePath) {
|
||||
super(Storage.Files.STORAGE, navigatePath);
|
||||
}
|
||||
|
||||
public boolean isListed(String command) {
|
||||
return isListed(command, false/*!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED*/);
|
||||
return isListed(command, false);
|
||||
}
|
||||
|
||||
public boolean isListed(String command, boolean ignoreColons) {
|
||||
final boolean caseSensitive = Storage.ConfigSections.Settings.BASE_COMMAND_CASE_SENSITIVE.ENABLED;
|
||||
final boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
|
||||
if (commands == null || command.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isNegated(command) && commands.contains("*")) {
|
||||
return true;
|
||||
boolean isNegated = Storage.Blacklist.BlockTypeFetcher.isNegated(command);
|
||||
|
||||
if (!isNegated == turn) {
|
||||
command = StringUtils.getFirstArg(command);
|
||||
}
|
||||
|
||||
for (String listedCommand : commands) {
|
||||
for (String listedCommand : hiddenCommands) {
|
||||
if (listedCommand == null)
|
||||
continue;
|
||||
|
||||
@@ -40,14 +44,14 @@ public class BlacklistStorage extends StorageTemplate implements Serializable {
|
||||
command = command.substring(command.indexOf(':'));
|
||||
}
|
||||
|
||||
if (caseSensitive) {
|
||||
if (StringUtils.getFirstArg(listedCommand).equals(StringUtils.getFirstArg(command))) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.getFirstArg(listedCommand).equalsIgnoreCase(StringUtils.getFirstArg(command))) {
|
||||
return true;
|
||||
}
|
||||
if (!isNegated == turn) {
|
||||
listedCommand = StringUtils.getFirstArg(listedCommand);
|
||||
}
|
||||
|
||||
if (caseSensitive && listedCommand.equals(command)) {
|
||||
return true;
|
||||
} else if (!caseSensitive && listedCommand.equalsIgnoreCase(command)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,14 +63,17 @@ public class BlacklistStorage extends StorageTemplate implements Serializable {
|
||||
}
|
||||
|
||||
public BlacklistStorage add(String command) {
|
||||
if (!commands.contains(command))
|
||||
if (!commands.contains(command)) {
|
||||
commands.add(command);
|
||||
hiddenCommands.add(command);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlacklistStorage remove(String command) {
|
||||
commands.remove(command);
|
||||
hiddenCommands.remove(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -79,6 +86,10 @@ public class BlacklistStorage extends StorageTemplate implements Serializable {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public List<String> getHiddenCommands() {
|
||||
return hiddenCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
getConfig().setAndSave(getNavigatePath(), commands);
|
||||
@@ -87,19 +98,54 @@ public class BlacklistStorage extends StorageTemplate implements Serializable {
|
||||
@Override
|
||||
public void load() {
|
||||
getConfig().reload();
|
||||
commands = (ArrayList<String>) getConfig().getOrSet(getNavigatePath(), commands);
|
||||
}
|
||||
|
||||
private boolean isNegated(String command) {
|
||||
if (command.isEmpty()) {
|
||||
return false;
|
||||
commands = (ArrayList<String>) getConfig().getOrSet(getNavigatePath(), commands);
|
||||
|
||||
final List<String> tmpCommands = commands != null ? new ArrayList<>(commands) : new ArrayList<>();
|
||||
final Set<String> pluginListCommands = new HashSet<>(), negatedPluginListCommands = new HashSet<>();
|
||||
|
||||
final String pluginCommandPrefix = "plugin=";
|
||||
final String negatedPluginCommandPrefix = Storage.Blacklist.BlockType.NEGATE + pluginCommandPrefix;
|
||||
|
||||
for (String command : tmpCommands) {
|
||||
if (command.startsWith(pluginCommandPrefix)) {
|
||||
pluginListCommands.add(command);
|
||||
}
|
||||
|
||||
if (command.startsWith(negatedPluginCommandPrefix)) {
|
||||
negatedPluginListCommands.add(command);
|
||||
}
|
||||
}
|
||||
|
||||
boolean negated = command.charAt(0) == '!';
|
||||
tmpCommands.removeAll(pluginListCommands);
|
||||
tmpCommands.removeAll(negatedPluginListCommands);
|
||||
|
||||
if (!negated && command.length() > 5)
|
||||
negated = command.charAt(5) == '!';
|
||||
for (String negatedPluginCommand : negatedPluginListCommands) {
|
||||
negatedPluginCommand = negatedPluginCommand.substring(negatedPluginCommandPrefix.length());
|
||||
|
||||
return negated;
|
||||
List<String> pluginCommands = Storage.getLoader().getPluginCommands(negatedPluginCommand, false);
|
||||
|
||||
for (String pluginCommand : pluginCommands) {
|
||||
tmpCommands.remove(pluginCommand);
|
||||
|
||||
tmpCommands.add(Storage.Blacklist.BlockType.NEGATE + pluginCommand);
|
||||
}
|
||||
}
|
||||
|
||||
for (String pluginListCommand : pluginListCommands) {
|
||||
pluginListCommand = pluginListCommand.substring(pluginCommandPrefix.length());
|
||||
|
||||
List<String> pluginCommands = Storage.getLoader().getPluginCommands(pluginListCommand, false);
|
||||
|
||||
for (String pluginCommand : pluginCommands) {
|
||||
final String negated = Storage.Blacklist.BlockType.NEGATE + pluginCommand;
|
||||
|
||||
if (!commands.contains(negated) && !tmpCommands.contains(negated)) {
|
||||
tmpCommands.add(pluginCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hiddenCommands = tmpCommands;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
package de.rayzs.pat.plugin;
|
||||
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.communication.impl.BukkitClient;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.plugin.converter.StorageConverter;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.plugin.process.CommandProcess;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
|
||||
import de.rayzs.pat.api.communication.BackendUpdater;
|
||||
import de.rayzs.pat.utils.adapter.GroupManagerAdapter;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import de.rayzs.pat.utils.group.TinyGroup;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.adapter.ViaVersionAdapter;
|
||||
@@ -18,13 +19,10 @@ import de.rayzs.pat.utils.adapter.LuckPermsAdapter;
|
||||
import de.rayzs.pat.plugin.commands.BukkitCommand;
|
||||
import de.rayzs.pat.utils.hooks.PlaceholderHook;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.*;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.plugin.metrics.bStats;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.response.action.ActionHandler;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -47,7 +45,6 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
|
||||
private static Plugin plugin;
|
||||
private static java.util.logging.Logger logger;
|
||||
private static boolean loaded = false, suggestions = false;
|
||||
private static Map<String, Command> commandsMap = null;
|
||||
private PATSchedulerTask updaterTask;
|
||||
|
||||
@@ -73,8 +70,9 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
|
||||
loadCommandMap();
|
||||
|
||||
CommandProcess.initialize();
|
||||
Reflection.initialize(getServer());
|
||||
|
||||
CommandProcess.initialize();
|
||||
ConfigUpdater.initialize();
|
||||
|
||||
Storage.initialize(this, getDescription().getVersion());
|
||||
@@ -92,7 +90,6 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
PluginManager manager = getServer().getPluginManager();
|
||||
|
||||
if (!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
loaded = true;
|
||||
GroupManager.initialize();
|
||||
BukkitPacketAnalyzer.injectAll();
|
||||
} else BackendUpdater.handle();
|
||||
@@ -100,12 +97,11 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
manager.registerEvents(new BukkitPlayerListener(), this);
|
||||
manager.registerEvents(new BukkitBlockCommandListener(), this);
|
||||
|
||||
if (Reflection.getMinor() >= 13) {
|
||||
suggestions = true;
|
||||
if (Reflection.isAtLeast(1, 13)) {
|
||||
manager.registerEvents(new BukkitAntiTabListener(), this);
|
||||
}
|
||||
|
||||
if (Reflection.isPaper() && Reflection.getMinor() >= 12)
|
||||
if (Reflection.isPaper() && Reflection.isAtLeast(1, 12))
|
||||
manager.registerEvents(new PaperServerListPing(), this);
|
||||
|
||||
registerCommand("proantitab", "pat");
|
||||
@@ -124,22 +120,24 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
}
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("ViaVersion") != null)
|
||||
if (getServer().getPluginManager().getPlugin("ViaVersion") != null) {
|
||||
ViaVersionAdapter.initialize();
|
||||
|
||||
if (Storage.USE_SIMPLECLOUD) {
|
||||
Logger.warning("Detected SimpleCloud. Therefore, MiniMessages are disabled!");
|
||||
}
|
||||
|
||||
Storage.broadcastPermissionsPluginNotice();
|
||||
ConfigUpdater.broadcastMissingParts();
|
||||
|
||||
ActionHandler.initialize();
|
||||
SubArgsModule.initialize();
|
||||
SubArguments.initialize();
|
||||
|
||||
StorageConverter.initialize();
|
||||
|
||||
PATScheduler.createScheduler(this::loadAllCommands);
|
||||
Communicator.initialize(new BukkitClient());
|
||||
|
||||
PATScheduler.createScheduler(() -> {
|
||||
Storage.reload();
|
||||
loadAllCommands();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,7 +206,10 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
|
||||
@Override
|
||||
public String getPlayerServerName(UUID uuid) {
|
||||
return null;
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) { return null; }
|
||||
|
||||
return player.getWorld().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -279,91 +280,81 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
}, 20L, 20L * Storage.ConfigSections.Settings.UPDATE.PERIOD);
|
||||
}
|
||||
|
||||
public static void handleUpdateCommandsPacket(CommunicationPackets.UpdateCommandsPacket packet) {
|
||||
public static void handleNotificationPacket(CommunicationPackets.Proxy2Backend.NotificationPacket packet) {
|
||||
if (!Storage.SEND_CONSOLE_NOTIFICATION) { return; }
|
||||
|
||||
if (!packet.hasTargetUUID()) {
|
||||
Bukkit.getOnlinePlayers().forEach(Player::updateCommands);
|
||||
final Player player = Bukkit.getPlayer(packet.playerId());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(packet.getTargetUUID());
|
||||
if (player != null) {
|
||||
player.updateCommands();
|
||||
}
|
||||
final List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
Storage.ConfigSections.Messages.NOTIFICATION.ALERT,
|
||||
"%player%", player.getName(),
|
||||
"%command%", packet.command(),
|
||||
"%server%", Storage.SERVER_NAME,
|
||||
"%world%", player.getWorld().getName());
|
||||
|
||||
Logger.info(notificationMessage);
|
||||
}
|
||||
|
||||
public static void synchronize(CommunicationPackets.PacketBundle packetBundle) {
|
||||
Storage.LAST_SYNC = System.currentTimeMillis();
|
||||
Communicator.sendFeedback();
|
||||
|
||||
CommunicationPackets.UnknownCommandPacket unknownCommandPacket = packetBundle.getUnknownCommandPacket();
|
||||
CommunicationPackets.CommandsPacket commandsPacket = packetBundle.getCommandsPacket();
|
||||
CommunicationPackets.GroupsPacket groupsPacket = packetBundle.getGroupsPacket();
|
||||
CommunicationPackets.NamespaceCommandsPacket namespaceCommandsPacket = packetBundle.getNamespaceCommandsPacket();
|
||||
CommunicationPackets.MessagePacket messagePacket = packetBundle.getMessagePacket();
|
||||
|
||||
boolean updatedList = false;
|
||||
|
||||
if (!messagePacket.getBaseBlockedMessage().getLines().isEmpty())
|
||||
Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE = messagePacket.getBaseBlockedMessage();
|
||||
|
||||
if (!messagePacket.getSubBlockedMessage().getLines().isEmpty())
|
||||
Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE = messagePacket.getSubBlockedMessage();
|
||||
|
||||
if (!messagePacket.getPrefix().isEmpty())
|
||||
Storage.ConfigSections.Messages.PREFIX.PREFIX = messagePacket.getPrefix();
|
||||
|
||||
if (Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.ENABLED != namespaceCommandsPacket.isEnabled())
|
||||
Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.ENABLED = namespaceCommandsPacket.isEnabled();
|
||||
|
||||
if (commandsPacket.getCommands() == null || commandsPacket.getCommands().isEmpty())
|
||||
Storage.Blacklist.getBlacklist().setList(new ArrayList<>());
|
||||
|
||||
else if (!ArrayUtils.compareStringArrays(Storage.Blacklist.getBlacklist().getCommands(), commandsPacket.getCommands())) {
|
||||
updatedList = true;
|
||||
Storage.Blacklist.getBlacklist().setList(commandsPacket.getCommands());
|
||||
public static void handleUpdateCommandsPacket(CommunicationPackets.Proxy2Backend.UpdatePacket packet) {
|
||||
if (Reflection.isBefore(1, 13)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED != commandsPacket.turnBlacklistToWhitelistEnabled())
|
||||
Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED = commandsPacket.turnBlacklistToWhitelistEnabled();
|
||||
|
||||
Map<String, List<String>> cpyCache = new HashMap<>();
|
||||
GroupManager.getGroups().forEach(group -> {
|
||||
cpyCache.put(group.getGroupName(), group.getCommands());
|
||||
});
|
||||
|
||||
GroupManager.clearAllGroups();
|
||||
|
||||
for (TinyGroup group : groupsPacket.getGroups()) {
|
||||
List<String> currentExistingList = cpyCache.get(group.getGroupName());
|
||||
if (
|
||||
!updatedList
|
||||
&& currentExistingList != null
|
||||
&& !ArrayUtils.compareStringArrays(currentExistingList, group.getCommands())
|
||||
) {
|
||||
updatedList = true;
|
||||
PATScheduler.createScheduler(() -> {
|
||||
if (packet.forEveryone()) {
|
||||
BukkitAntiTabListener.updateCommands();
|
||||
return;
|
||||
}
|
||||
|
||||
GroupManager.setGroup(group.getGroupName(), group.getPriority(), group.getCommands());
|
||||
Player player = Bukkit.getPlayer(packet.playerId());
|
||||
if (player != null) {
|
||||
BukkitAntiTabListener.updateCommands(player);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static void handlePlayerExecuteCommandPacket(CommunicationPackets.Proxy2Backend.ExecutePlayerCommandPacket packet) {
|
||||
if (isP2BDisabled()) return;
|
||||
|
||||
final Player player = Bukkit.getPlayer(packet.playerId());
|
||||
if (player == null) return;
|
||||
|
||||
PATScheduler.execute(() -> Bukkit.dispatchCommand(player, packet.command()), player);
|
||||
}
|
||||
|
||||
public static void handleConsoleExecuteCommandPacket(CommunicationPackets.Proxy2Backend.ExecuteConsoleCommandPacket packet) {
|
||||
if (isP2BDisabled()) return;
|
||||
|
||||
PATScheduler.execute(() -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), packet.command()), null);
|
||||
}
|
||||
|
||||
public static void handleConsoleMessagePacket(CommunicationPackets.Proxy2Backend.ConsoleMessagePacket packet) {
|
||||
if (isP2BDisabled()) return;
|
||||
|
||||
Logger.info(packet.message());
|
||||
}
|
||||
|
||||
private static boolean isP2BDisabled() {
|
||||
if (!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ALLOW_P2B_ACTIONS) {
|
||||
Logger.warning("P2B actions are currently disabled! You need to enable them manually.");
|
||||
Logger.warning("For that, go to your 'plugins/ProAntiTab/config.yml' file and enable 'handle-through-proxy -> allow-p2b-actions'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE = unknownCommandPacket.getMessage();
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED != unknownCommandPacket.isEnabled())
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED = unknownCommandPacket.isEnabled();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loaded) {
|
||||
loaded = true;
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
CommandSender sender = CommandSenderHandler.from(player);
|
||||
sender.updateGroups();
|
||||
});
|
||||
}
|
||||
public static void handleDataSyncPacket(CommunicationPackets.Proxy2Backend.DataSyncPacket packet) {
|
||||
Storage.ConfigSections.Messages.PREFIX.PREFIX = packet.messages().prefix();
|
||||
Storage.ConfigSections.Settings.AUTO_LOWERCASE_COMMANDS.ENABLED = packet.autoLowerCase().enabled();
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED = packet.unknownCommand().enabled();
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE = packet.unknownCommand().message();
|
||||
|
||||
if (Reflection.getMinor() >= 13 && updatedList) {
|
||||
BukkitAntiTabListener.updateCommands();
|
||||
}
|
||||
|
||||
PATEventHandler.callReceiveSyncEvents(packetBundle);
|
||||
PATEventHandler.callReceiveSyncEvents(packet);
|
||||
}
|
||||
|
||||
public static List<String> getAllCommands() {
|
||||
@@ -394,6 +385,48 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
return pluginNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllCommands(boolean useColons) {
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, Command> entry : BukkitLoader.getCommandsMap().entrySet()) {
|
||||
if (entry.getKey().toLowerCase().contains(":")) {
|
||||
String command = entry.getKey().substring(entry.getKey().lastIndexOf(":") + 1);
|
||||
|
||||
commands.add(command);
|
||||
|
||||
if (useColons) {
|
||||
commands.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPluginCommands(String pluginName, boolean useColons) {
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
if (pluginName.isBlank()) return commands;
|
||||
|
||||
pluginName = pluginName.toLowerCase();
|
||||
|
||||
for (Map.Entry<String, Command> entry : BukkitLoader.getCommandsMap().entrySet()) {
|
||||
if (entry.getKey().toLowerCase().startsWith(pluginName + ":")) {
|
||||
String command = entry.getKey().substring(pluginName.length() + 1);
|
||||
|
||||
commands.add(command);
|
||||
|
||||
if (useColons) {
|
||||
commands.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private void loadCommandMap() {
|
||||
try {
|
||||
if (Bukkit.getPluginManager() instanceof SimplePluginManager) {
|
||||
@@ -462,10 +495,6 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
return commandsMap;
|
||||
}
|
||||
|
||||
public static boolean useSuggestions() {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
public static Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
@@ -473,8 +502,4 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
public static java.util.logging.Logger getPluginLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static boolean isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,10 @@ package de.rayzs.pat.plugin;
|
||||
|
||||
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.communication.impl.BungeeClient;
|
||||
import de.rayzs.pat.plugin.converter.StorageConverter;
|
||||
import de.rayzs.pat.plugin.process.CommandProcess;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.api.netty.proxy.BungeePacketAnalyzer;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
@@ -50,11 +51,10 @@ public class BungeeLoader extends Plugin implements PluginLoader {
|
||||
plugin = this;
|
||||
logger = getLogger();
|
||||
|
||||
CommandProcess.initialize();
|
||||
Reflection.initialize(getProxy());
|
||||
ConfigUpdater.initialize();
|
||||
|
||||
Storage.USE_SIMPLECLOUD = Reflection.doesClassExist("eu.thesimplecloud.plugin.startup.CloudPlugin");
|
||||
CommandProcess.initialize();
|
||||
ConfigUpdater.initialize();
|
||||
|
||||
Storage.initialize(this, getDescription().getVersion());
|
||||
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
|
||||
@@ -79,9 +79,6 @@ public class BungeeLoader extends Plugin implements PluginLoader {
|
||||
|
||||
startUpdaterTask();
|
||||
|
||||
if (!Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED)
|
||||
ProxyServer.getInstance().getScheduler().schedule(this, Communicator::syncData, 5, TimeUnit.SECONDS);
|
||||
|
||||
Storage.PLUGIN_OBJECT = this;
|
||||
|
||||
if (manager.getPlugin("LuckPerms") != null)
|
||||
@@ -92,23 +89,24 @@ public class BungeeLoader extends Plugin implements PluginLoader {
|
||||
Logger.info("Successfully hooked into PAPIProxyBridge!");
|
||||
}
|
||||
|
||||
if(Storage.USE_SIMPLECLOUD)
|
||||
Logger.warning("Detected SimpleCloud and therefore MiniMessages by Kyori are disabled!");
|
||||
|
||||
BungeePacketAnalyzer.injectAll();
|
||||
|
||||
Storage.broadcastPermissionsPluginNotice();
|
||||
ConfigUpdater.broadcastMissingParts();
|
||||
|
||||
ActionHandler.initialize();
|
||||
SubArgsModule.initialize();
|
||||
SubArguments.initialize();
|
||||
|
||||
StorageConverter.initialize();
|
||||
|
||||
Communicator.initialize(new BungeeClient());
|
||||
|
||||
// Reload proxy commands after 1, 5, and 15 seconds.
|
||||
for (int i : new Integer[] { 1, 5, 15 }) {
|
||||
ProxyServer.getInstance().getScheduler().schedule(this, BungeePacketAnalyzer::loadProxyCommands, i, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
BungeePacketAnalyzer.injectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,7 +133,7 @@ public class BungeeLoader extends Plugin implements PluginLoader {
|
||||
PermissionUtil.reloadPermissions();
|
||||
Storage.getLoader().updateCommandCache();
|
||||
|
||||
Communicator.sendRequest();
|
||||
Communicator.Proxy2Backend.sendUpdateCommand();
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@@ -144,6 +142,11 @@ public class BungeeLoader extends Plugin implements PluginLoader {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllCommands(boolean useColons) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getConsoleSender() {
|
||||
return ProxyServer.getInstance().getConsole();
|
||||
@@ -171,10 +174,16 @@ public class BungeeLoader extends Plugin implements PluginLoader {
|
||||
|
||||
@Override
|
||||
public String getPlayerServerName(UUID uuid) {
|
||||
final String cachedServerName = Storage.getCachedPlayerServername(uuid);
|
||||
if (cachedServerName != null) {
|
||||
return cachedServerName;
|
||||
}
|
||||
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
|
||||
if (player == null || player.getServer() == null || player.getServer().getInfo() == null)
|
||||
if (player == null || player.getServer() == null || player.getServer().getInfo() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return player.getServer().getInfo().getName();
|
||||
}
|
||||
@@ -272,6 +281,11 @@ public class BungeeLoader extends Plugin implements PluginLoader {
|
||||
return pluginNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPluginCommands(String pluginName, boolean useColons) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
public void startUpdaterTask() {
|
||||
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED)
|
||||
return;
|
||||
|
||||
@@ -41,6 +41,9 @@ public interface PluginLoader {
|
||||
List<String> getOnlinePlayerNames();
|
||||
List<String> getOfflinePlayerNames();
|
||||
|
||||
List<String> getAllCommands(boolean useColons);
|
||||
List<String> getPluginCommands(String pluginName, boolean useColons);
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* %n = Plugin name
|
||||
|
||||
@@ -5,9 +5,11 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.communication.impl.VelocityClient;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.netty.proxy.VelocityPacketAnalyzer;
|
||||
import de.rayzs.pat.plugin.converter.StorageConverter;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.plugin.process.CommandProcess;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.plugin.metrics.impl.VelocityMetrics;
|
||||
@@ -38,9 +40,9 @@ import java.util.*;
|
||||
|
||||
@Plugin(name = "ProAntiTab",
|
||||
id = "proantitab",
|
||||
version = "2.1.2",
|
||||
version = "2.3.2",
|
||||
authors = "Rayzs_YT",
|
||||
description = "Hide more than just your plugins. Hide almost everything!",
|
||||
description = "Hides more than just your plugins.",
|
||||
url = "https://www.rayzs.de/products/proantitab/page",
|
||||
dependencies = {
|
||||
@Dependency(id = "luckperms", optional = true),
|
||||
@@ -78,11 +80,11 @@ public class VelocityLoader implements PluginLoader {
|
||||
Configurator.createResourcedFile("files\\proxy-placeholders.yml", "placeholders.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-custom-responses.yml", "custom-responses.yml", false);
|
||||
|
||||
CommandProcess.initialize();
|
||||
Reflection.initialize(server);
|
||||
|
||||
CommandProcess.initialize();
|
||||
ConfigUpdater.initialize();
|
||||
|
||||
Storage.USE_SIMPLECLOUD = Reflection.doesClassExist("eu.thesimplecloud.plugin.startup.CloudPlugin");
|
||||
Storage.initialize(this, pluginContainer.getDescription().getVersion().get());
|
||||
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
|
||||
|
||||
@@ -101,9 +103,6 @@ public class VelocityLoader implements PluginLoader {
|
||||
|
||||
startUpdaterTask();
|
||||
|
||||
if (!Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED)
|
||||
server.getScheduler().buildTask(this, Communicator::syncData).delay(5, TimeUnit.SECONDS).schedule();
|
||||
|
||||
Storage.PLUGIN_OBJECT = this;
|
||||
|
||||
if (server.getPluginManager().getPlugin("luckperms").isPresent())
|
||||
@@ -114,16 +113,17 @@ public class VelocityLoader implements PluginLoader {
|
||||
Logger.info("Successfully hooked into PAPIProxyBridge!");
|
||||
}
|
||||
|
||||
if(Storage.USE_SIMPLECLOUD)
|
||||
Logger.warning("Detected SimpleCloud and therefore MiniMessages by Kyori are disabled!");
|
||||
|
||||
Storage.broadcastPermissionsPluginNotice();
|
||||
ConfigUpdater.broadcastMissingParts();
|
||||
|
||||
ActionHandler.initialize();
|
||||
SubArgsModule.initialize();
|
||||
SubArguments.initialize();
|
||||
|
||||
StorageConverter.initialize();
|
||||
|
||||
Communicator.initialize(new VelocityClient());
|
||||
|
||||
VelocityPacketAnalyzer.injectAll();
|
||||
}
|
||||
|
||||
public static org.slf4j.Logger getPluginLogger() {
|
||||
@@ -141,9 +141,9 @@ public class VelocityLoader implements PluginLoader {
|
||||
public static void delayedPlayerReload(UUID uuid) {
|
||||
server.getScheduler().buildTask(VelocityLoader.instance, () -> {
|
||||
String serverName = Storage.getLoader().getPlayerServerName(uuid);
|
||||
List<String> commands = new ArrayList<>(SubArgsModule.getServerCommands(serverName));
|
||||
List<String> commands = new ArrayList<>(SubArguments.getServerCommands(serverName));
|
||||
|
||||
commands.addAll(SubArgsModule.getGroupCommands(uuid, serverName));
|
||||
commands.addAll(SubArguments.getGroupCommands(uuid, serverName));
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(uuid, commands, true);
|
||||
}).delay(1, TimeUnit.SECONDS).schedule();
|
||||
@@ -157,6 +157,11 @@ public class VelocityLoader implements PluginLoader {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllCommands(boolean useColons) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getConsoleSender() {
|
||||
return server.getConsoleCommandSource();
|
||||
@@ -213,6 +218,11 @@ public class VelocityLoader implements PluginLoader {
|
||||
|
||||
@Override
|
||||
public String getPlayerServerName(UUID uuid) {
|
||||
final String cachedServerName = Storage.getCachedPlayerServername(uuid);
|
||||
if (cachedServerName != null) {
|
||||
return cachedServerName;
|
||||
}
|
||||
|
||||
Optional<Player> optPlayer = server.getPlayer(uuid);
|
||||
|
||||
if (optPlayer.isEmpty())
|
||||
@@ -221,8 +231,9 @@ public class VelocityLoader implements PluginLoader {
|
||||
Player player = optPlayer.get();
|
||||
Optional<ServerConnection> optConnection = player.getCurrentServer();
|
||||
|
||||
if (optConnection.isEmpty())
|
||||
if (optConnection.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ServerConnection connection = optConnection.get();
|
||||
return connection.getServer().getServerInfo().getName();
|
||||
@@ -297,6 +308,11 @@ public class VelocityLoader implements PluginLoader {
|
||||
return pluginNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPluginCommands(String pluginName, boolean useColons) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
public void startUpdaterTask() {
|
||||
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED) return;
|
||||
|
||||
|
||||
+4
-1
@@ -24,7 +24,10 @@ public class CommandWhitelistConverter extends Converter {
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
final List<String> l1 = (ArrayList<String>) config.get("groups." + groupName + ".commands");
|
||||
final List<String> l2 = (ArrayList<String>) config.get("groups." + groupName + ".subcommands");
|
||||
final List<String> l2 = ((ArrayList<String>) config.get("groups." + groupName + ".subcommands"))
|
||||
.stream()
|
||||
.map(c -> Storage.Blacklist.BlockType.NEGATE + c)
|
||||
.toList();
|
||||
|
||||
commands.addAll(l1);
|
||||
commands.addAll(l2);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package de.rayzs.pat.plugin.listeners.bukkit;
|
||||
|
||||
import de.rayzs.pat.api.event.events.FilteredSuggestionEvent;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.scheduler.PATScheduler;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
@@ -23,10 +26,11 @@ public class BukkitAntiTabListener implements Listener {
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void onPlayerCommandSend(PlayerCommandSendEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
final UUID uuid = player.getUniqueId();
|
||||
|
||||
|
||||
if (Storage.USE_VELOCITY) {
|
||||
if (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,15 +42,6 @@ public class BukkitAntiTabListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!BukkitLoader.isLoaded()) {
|
||||
event.getCommands().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getCommands().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -57,15 +52,26 @@ public class BukkitAntiTabListener implements Listener {
|
||||
if (!player.isOp() && knownOperators.contains(uuid)) {
|
||||
knownOperators.remove(uuid);
|
||||
|
||||
CommandSender sender = CommandSenderHandler.getSenderFromUUID(uuid);
|
||||
PermissionUtil.reloadPermissions(sender);
|
||||
if (Reflection.isCraftbukkit() && sender != null) {
|
||||
PermissionUtil.reloadPermissions(sender);
|
||||
} else {
|
||||
PermissionUtil.reloadPermissions(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player)) {
|
||||
if (PermissionUtil.hasBypassPermission(sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<String> playerCommands = COMMANDS_CACHE.getPlayerCommands(new ArrayList<>(event.getCommands()), player);
|
||||
if (Reflection.isCraftbukkit() && !Bukkit.getOnlinePlayers().contains(player)) {
|
||||
event.getCommands().clear();
|
||||
|
||||
PATScheduler.createScheduler(player::updateCommands, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
final List<String> playerCommands = COMMANDS_CACHE.getPlayerCommands(new ArrayList<>(event.getCommands()), sender, groups);
|
||||
final FilteredSuggestionEvent filteredSuggestionEvent = PATEventHandler.callFilteredSuggestionEvents(player, playerCommands);
|
||||
|
||||
event.getCommands().clear();
|
||||
@@ -91,7 +97,7 @@ public class BukkitAntiTabListener implements Listener {
|
||||
}
|
||||
|
||||
private static boolean notUpdatablePlayer(UUID uuid) {
|
||||
return Storage.USE_VIAVERSION && Reflection.getMinor() >= 16 && ViaVersionAdapter.getPlayerProtocol(uuid) < 754;
|
||||
return Storage.USE_VIAVERSION && Reflection.isAtLeast(1, 16) && ViaVersionAdapter.getPlayerProtocol(uuid) < 754;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +108,7 @@ public class BukkitAntiTabListener implements Listener {
|
||||
}
|
||||
|
||||
public static void updateCommands(Player player) {
|
||||
if (Reflection.getMinor() >= 13 && !notUpdatablePlayer(player.getUniqueId()))
|
||||
if (!notUpdatablePlayer(player.getUniqueId()))
|
||||
player.updateCommands();
|
||||
}
|
||||
|
||||
|
||||
+37
-14
@@ -2,6 +2,10 @@ package de.rayzs.pat.plugin.listeners.bukkit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -22,15 +26,16 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
|
||||
@EventHandler (priority = EventPriority.HIGHEST)
|
||||
public void onUnknownCommandRecognition(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
final Player player = event.getPlayer();
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
final World world = player.getWorld();
|
||||
|
||||
String rawCommand = StringUtils.getFirstArg(event.getMessage()),
|
||||
command = rawCommand.substring(1);
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED || event.isCancelled()) return;
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player))
|
||||
if (PermissionUtil.hasBypassPermission(sender))
|
||||
return;
|
||||
|
||||
if (Storage.getLoader().doesCommandExist(command))
|
||||
@@ -45,7 +50,9 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void onPlayerCommandProcess(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
final Player player = event.getPlayer();
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
|
||||
final String commandFirstArg = StringUtils.getFirstArg(event.getMessage());
|
||||
|
||||
if (Storage.ConfigSections.Settings.AUTO_LOWERCASE_COMMANDS.isCommand(commandFirstArg)) {
|
||||
@@ -71,6 +78,14 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
command = command.substring(1);
|
||||
command = StringUtils.getFirstArg(command);
|
||||
|
||||
if (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(sender, command)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String displayCommand = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
@@ -79,10 +94,6 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
"%command%", displayCommand,
|
||||
"%world%", worldName);
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player, command)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command)) {
|
||||
|
||||
MessageTranslator.send(
|
||||
@@ -127,13 +138,25 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED)
|
||||
return;
|
||||
|
||||
if (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED)
|
||||
return;
|
||||
final boolean cancelBlockedCommand = Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED;
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
if (!Storage.Blacklist.canPlayerAccessChat(player, command)) {
|
||||
boolean allowed = Storage.Blacklist.canPlayerAccessChat(sender, groups, command);
|
||||
boolean blockedNamespace = false;
|
||||
|
||||
if (!Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(sender)) {
|
||||
blockedNamespace = cancelBlockedCommand
|
||||
? Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command)
|
||||
: Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesAlwaysBlock(command);
|
||||
|
||||
if (blockedNamespace) allowed = false;
|
||||
}
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED && !blockedNamespace) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allowed) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
|
||||
player,
|
||||
event.getMessage(),
|
||||
|
||||
@@ -6,8 +6,8 @@ import de.rayzs.pat.api.event.events.ServerPlayersChangeEvent;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
|
||||
import de.rayzs.pat.api.communication.BackendUpdater;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionPlugin;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
@@ -18,9 +18,6 @@ import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitPlayerListener implements Listener {
|
||||
@@ -53,11 +50,9 @@ public class BukkitPlayerListener implements Listener {
|
||||
|
||||
if (Storage.getPermissionPlugin() == PermissionPlugin.GROUPMANAGER) {
|
||||
PermissionUtil.reloadPermissions(sender);
|
||||
} else {
|
||||
sender.updateGroups();
|
||||
}
|
||||
|
||||
if (Reflection.getMinor() >= 13) {
|
||||
if (Reflection.isAtLeast(1, 13)) {
|
||||
BukkitAntiTabListener.handleTabCompletion(player);
|
||||
}
|
||||
}, 20);
|
||||
@@ -69,19 +64,30 @@ public class BukkitPlayerListener implements Listener {
|
||||
PATScheduler.createScheduler(() -> {
|
||||
if (player.isOnline()) {
|
||||
if (!BukkitPacketAnalyzer.inject(player)) {
|
||||
Logger.warning("Failed to inject into player! (" + player.getName() + ")" );
|
||||
player.kickPlayer("Failed to inject player!");
|
||||
|
||||
if (Storage.ConfigSections.Settings.INJECTION_FAILED.ENABLED) {
|
||||
|
||||
Logger.info(MessageTranslator.replaceMessage(
|
||||
sender,
|
||||
Storage.ConfigSections.Settings.INJECTION_FAILED.CONSOLE_MESSAGE
|
||||
));
|
||||
|
||||
player.kickPlayer(MessageTranslator.replaceMessage(
|
||||
sender,
|
||||
Storage.ConfigSections.Settings.INJECTION_FAILED.KICK_MESSAGE
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
|
||||
// Update sub arguments for <1.12.2 servers.
|
||||
if (Reflection.getMinor() < 13) {
|
||||
if (Reflection.isBefore(1, 13)) {
|
||||
Storage.quickSubArgumentUpdate(uuid);
|
||||
}
|
||||
|
||||
if (Storage.OUTDATED && PermissionUtil.hasPermission(player, "joinupdate")) {
|
||||
if (Storage.OUTDATED && PermissionUtil.hasPermission(sender, "joinupdate")) {
|
||||
PATScheduler.createScheduler(() -> {
|
||||
if (player.isOnline()) {
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines());
|
||||
@@ -113,7 +119,7 @@ public class BukkitPlayerListener implements Listener {
|
||||
assert sender != null;
|
||||
PermissionUtil.reloadPermissions(sender);
|
||||
|
||||
if (Reflection.getMinor() >= 13) {
|
||||
if (Reflection.isAtLeast(1, 13)) {
|
||||
BukkitAntiTabListener.handleTabCompletion(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ public class PaperServerListPing implements Listener {
|
||||
String versionName = Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PROTOCOL.replace("%online_extended%", String.valueOf(onlineExtend)).replace("%online%", String.valueOf(online)).replace("%max%", String.valueOf(max));
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.HIDE_PLAYERS) {
|
||||
event.getPlayerSample().clear();
|
||||
event.setHidePlayers(true);
|
||||
}
|
||||
|
||||
else if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_CUSTOM_PLAYERLIST) {
|
||||
|
||||
@@ -2,27 +2,48 @@ package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import de.rayzs.pat.api.netty.proxy.BungeePacketAnalyzer;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.TabCompleteEvent;
|
||||
import net.md_5.bungee.api.event.TabCompleteResponseEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeAntiTabListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(TabCompleteEvent event) {
|
||||
if(!(event.getSender() instanceof ProxiedPlayer)) return;
|
||||
public void onTabCompleteResponse(TabCompleteResponseEvent event) {
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if(!(event.getReceiver() instanceof ProxiedPlayer)) return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
CommandSender sender = CommandSenderHandler.from(player);
|
||||
|
||||
ServerInfo serverInfo = player.getServer().getInfo();
|
||||
String serverName = serverInfo.getName();
|
||||
String cursor = event.getCursor().substring(1);
|
||||
|
||||
String rawCursor = BungeePacketAnalyzer.getPlayerInput(player);
|
||||
|
||||
if (rawCursor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rawCursor.startsWith("/")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String cursor = rawCursor.substring(1);
|
||||
|
||||
if (event.getSuggestions().isEmpty())
|
||||
return;
|
||||
@@ -30,19 +51,63 @@ public class BungeeAntiTabListener implements Listener {
|
||||
if (Storage.Blacklist.isDisabledServer(serverName))
|
||||
return;
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player))
|
||||
if (PermissionUtil.hasBypassPermission(sender))
|
||||
return;
|
||||
|
||||
FilteredTabCompletionEvent filteredTabCompletionEvent = PATEventHandler.callFilteredTabCompletionEvents(player, cursor, event.getSuggestions());
|
||||
List<String> suggestions = filteredTabCompletionEvent.getCompletion();
|
||||
|
||||
event.getSuggestions().removeIf(suggestion -> {
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(suggestion) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(suggestion)) {
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
final boolean doesBypassNamespace = Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(sender);
|
||||
final boolean spaces = cursor.contains(" ");
|
||||
|
||||
boolean cancelsBeforeHand = false;
|
||||
|
||||
if (Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(cursor) && !doesBypassNamespace) {
|
||||
cancelsBeforeHand = true;
|
||||
}
|
||||
|
||||
if (!cancelsBeforeHand && !cursor.isEmpty()) {
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(sender, groups, StringUtils.getFirstArg(cursor), serverName);
|
||||
}
|
||||
|
||||
if (!cancelsBeforeHand) {
|
||||
cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(cursor) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(cursor);
|
||||
}
|
||||
|
||||
if (spaces) {
|
||||
if (cancelsBeforeHand) {
|
||||
event.getSuggestions().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
FilteredTabCompletionEvent filteredTabCompletionEvent = PATEventHandler.callFilteredTabCompletionEvents(player.getUniqueId(), rawCursor, new ArrayList<>(event.getSuggestions()));
|
||||
|
||||
if (filteredTabCompletionEvent.isCancelled()) {
|
||||
event.getSuggestions().clear();
|
||||
} else {
|
||||
event.getSuggestions().removeIf(s -> !filteredTabCompletionEvent.getCompletion().contains(s));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
event.getSuggestions().removeIf(s -> {
|
||||
String cpy = s;
|
||||
if (cpy.startsWith("/")) {
|
||||
cpy = cpy.substring(1);
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(cpy) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(cpy)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !suggestions.contains(suggestion);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(sender, groups, cpy, serverName);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(TabCompleteEvent event) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
BungeePacketAnalyzer.setPlayerInput(player, event.getCursor());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
@@ -20,24 +25,30 @@ public class BungeeBlockCommandListener implements Listener {
|
||||
public void onChat(ChatEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
Connection connection = event.getSender();
|
||||
final Connection connection = event.getSender();
|
||||
if (! (connection instanceof ProxiedPlayer) || !event.getMessage().startsWith("/"))
|
||||
return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) connection;
|
||||
String serverName = player.getServer().getInfo().getName();
|
||||
final ProxiedPlayer player = (ProxiedPlayer) connection;
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
final String serverName = player.getServer().getInfo().getName();
|
||||
|
||||
String command = event.getMessage();
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player, command) || Storage.Blacklist.isDisabledServer(serverName))
|
||||
if (PermissionUtil.hasBypassPermission(sender, command) || Storage.Blacklist.isDisabledServer(serverName))
|
||||
return;
|
||||
|
||||
command = command.startsWith("/") ? command.substring(1) : command;
|
||||
command = StringUtils.getFirstArg(command);
|
||||
|
||||
if (Communicator.get().hasConnectedClients() && Storage.ConfigSections.Settings.AUTO_LOWERCASE_COMMANDS.isCommand(command)) {
|
||||
command = command.toLowerCase();
|
||||
}
|
||||
|
||||
final String displayCommand = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
final List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
Storage.ConfigSections.Messages.NOTIFICATION.ALERT,
|
||||
"%player%", player.getName(),
|
||||
"%command%", displayCommand,
|
||||
@@ -45,6 +56,8 @@ public class BungeeBlockCommandListener implements Listener {
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command)) {
|
||||
|
||||
Communicator.Proxy2Backend.sendNotification(player.getUniqueId(), serverName, displayCommand);
|
||||
|
||||
MessageTranslator.send(
|
||||
player,
|
||||
Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE,
|
||||
@@ -67,6 +80,8 @@ public class BungeeBlockCommandListener implements Listener {
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(command)) {
|
||||
|
||||
Communicator.Proxy2Backend.sendNotification(player.getUniqueId(), serverName, displayCommand);
|
||||
|
||||
MessageTranslator.send(
|
||||
player,
|
||||
Storage.ConfigSections.Settings.CUSTOM_VERSION.MESSAGE,
|
||||
@@ -87,10 +102,25 @@ public class BungeeBlockCommandListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED)
|
||||
return;
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
final boolean cancelBlockedCommand = Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED;
|
||||
|
||||
if (!Storage.Blacklist.canPlayerAccessChat(player, command, serverName)) {
|
||||
boolean allowed = Storage.Blacklist.canPlayerAccessChat(sender, groups, command, serverName);
|
||||
boolean blockedNamespace = false;
|
||||
|
||||
if (!Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(sender)) {
|
||||
blockedNamespace = cancelBlockedCommand
|
||||
? Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command)
|
||||
: Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesAlwaysBlock(command);
|
||||
|
||||
if (blockedNamespace) allowed = false;
|
||||
}
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED && !blockedNamespace) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allowed) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
|
||||
player,
|
||||
event.getMessage(),
|
||||
@@ -104,6 +134,8 @@ public class BungeeBlockCommandListener implements Listener {
|
||||
if (!executeCommandEvent.doesNotify())
|
||||
return;
|
||||
|
||||
Communicator.Proxy2Backend.sendNotification(player.getUniqueId(), serverName, displayCommand);
|
||||
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
Logger.info(notificationMessage);
|
||||
|
||||
|
||||
+1
-2
@@ -33,9 +33,8 @@ public class BungeePlayerConnectionListener implements Listener {
|
||||
}, 500, TimeUnit.MILLISECONDS);
|
||||
|
||||
PermissionUtil.setPlayerPermissions(sender);
|
||||
sender.updateGroups();
|
||||
|
||||
if(Storage.OUTDATED && PermissionUtil.hasPermission(player, "joinupdate")) {
|
||||
if (Storage.OUTDATED && PermissionUtil.hasPermission(sender, "joinupdate")) {
|
||||
ProxyServer.getInstance().getScheduler().schedule(BungeeLoader.getPlugin(), () -> {
|
||||
if (player.isConnected()) {
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.UPDATE.OUTDATED, "%player%", player.getName());
|
||||
|
||||
@@ -9,7 +9,11 @@ import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.FilteredSuggestionEvent;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
@@ -21,27 +25,33 @@ public class WaterfallAntiTabListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onProxyDefineCommands(ProxyDefineCommandsEvent event) {
|
||||
if(!(event.getReceiver() instanceof ProxiedPlayer) || event.getCommands().isEmpty()) return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
String serverName = player.getServer().getInfo().getName();
|
||||
|
||||
if (Storage.Blacklist.isDisabledServer(serverName) || PermissionUtil.hasBypassPermission(player))
|
||||
if (!(event.getReceiver() instanceof ProxiedPlayer) || event.getCommands().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
final ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
final String serverName = player.getServer().getInfo().getName();
|
||||
|
||||
if(!cache.containsKey(serverName))
|
||||
if (Storage.Blacklist.isDisabledServer(serverName) || PermissionUtil.hasBypassPermission(sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
final Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
|
||||
if (!cache.containsKey(serverName)) {
|
||||
cache.put(serverName, new CommandsCache());
|
||||
}
|
||||
|
||||
CommandsCache commandsCache = cache.get(serverName);
|
||||
List<String> commandsAsString = new ArrayList<>();
|
||||
HashMap<String, Command> commandsMap = new HashMap<>(event.getCommands());
|
||||
final CommandsCache commandsCache = cache.get(serverName);
|
||||
final List<String> commandsAsString = new ArrayList<>();
|
||||
final HashMap<String, Command> commandsMap = new HashMap<>(event.getCommands());
|
||||
|
||||
event.getCommands().forEach((key, value) -> commandsAsString.add(key));
|
||||
commandsCache.handleCommands(commandsAsString, serverName);
|
||||
|
||||
List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, serverName);
|
||||
List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, sender, groups, serverName);
|
||||
event.getCommands().entrySet().removeIf(command -> {
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(command.getKey()) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(command.getKey())) {
|
||||
|
||||
@@ -16,7 +16,11 @@ import de.rayzs.pat.api.event.events.FilteredSuggestionEvent;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
|
||||
public class VelocityAntiTabListener {
|
||||
|
||||
@@ -28,25 +32,32 @@ public class VelocityAntiTabListener {
|
||||
|
||||
@Subscribe (order = PostOrder.LAST)
|
||||
public void onTabComplete(TabCompleteEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (!event.getPartialMessage().startsWith("/")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String serverName = player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "unknown";
|
||||
final String serverName = player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "unknown";
|
||||
|
||||
if (Storage.Blacklist.isDisabledServer(serverName))
|
||||
if (Storage.Blacklist.isDisabledServer(serverName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player) || event.getSuggestions().isEmpty() || !player.getCurrentServer().isPresent()) return;
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(sender) || event.getSuggestions().isEmpty() || player.getCurrentServer().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
event.getSuggestions().removeIf(command -> {
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(command) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(command)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, command, serverName);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(sender, groups, command, serverName);
|
||||
});
|
||||
|
||||
FilteredSuggestionEvent filteredSuggestionEvent = PATEventHandler.callFilteredSuggestionEvents(player, event.getSuggestions());
|
||||
@@ -56,17 +67,19 @@ public class VelocityAntiTabListener {
|
||||
@Subscribe (order = PostOrder.LAST)
|
||||
public void onPlayerAvailableCommands(PlayerAvailableCommandsEvent event) {
|
||||
try {
|
||||
Player player = event.getPlayer();
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (event.getRootNode().getChildren().isEmpty() || !player.getCurrentServer().isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player)) {
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
|
||||
final String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
|
||||
|
||||
if (Storage.Blacklist.isDisabledServer(serverName)) {
|
||||
return;
|
||||
@@ -78,14 +91,18 @@ public class VelocityAntiTabListener {
|
||||
cache.put(serverName, new CommandsCache());
|
||||
}
|
||||
|
||||
CommandsCache commandsCache = cache.get(serverName);
|
||||
final CommandsCache commandsCache = cache.get(serverName);
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
final List<String> commandsAsString = new ArrayList<>();
|
||||
|
||||
event.getRootNode().getChildren().stream()
|
||||
.filter(command -> command != null && command.getName() != null)
|
||||
.forEach(command -> commandsAsString.add(command.getName()));
|
||||
|
||||
List<String> commandsAsString = new ArrayList<>();
|
||||
event.getRootNode().getChildren().stream().filter(command -> command != null && command.getName() != null).forEach(command -> commandsAsString.add(command.getName()));
|
||||
commandsCache.handleCommands(commandsAsString, serverName);
|
||||
|
||||
final boolean newer = player.getProtocolVersion().getProtocol() > 340, argsChildrenExist = event.getRootNode().getChild("args") != null;
|
||||
final List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, serverName);
|
||||
final List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, sender, groups, serverName);
|
||||
|
||||
if (event.getRootNode().getChildren().size() == 1
|
||||
&& newer && argsChildrenExist
|
||||
|
||||
+54
-14
@@ -3,13 +3,19 @@ package de.rayzs.pat.plugin.listeners.velocity;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.api.event.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityBlockCommandListener {
|
||||
@@ -24,29 +30,36 @@ public class VelocityBlockCommandListener {
|
||||
}
|
||||
|
||||
public static CommandExecuteEvent handleCommand(CommandExecuteEvent event) {
|
||||
if(!event.getResult().isAllowed())
|
||||
if (!event.getResult().isAllowed()) {
|
||||
return event;
|
||||
}
|
||||
|
||||
CommandSource commandSource = event.getCommandSource();
|
||||
Object consoleSender = Storage.getLoader().getConsoleSender();
|
||||
final CommandSource commandSource = event.getCommandSource();
|
||||
final Object consoleSender = Storage.getLoader().getConsoleSender();
|
||||
|
||||
if(! (commandSource instanceof Player))
|
||||
return event;
|
||||
|
||||
Player player = (Player) commandSource;
|
||||
String command = StringUtils.getFirstArg(event.getCommand());
|
||||
|
||||
String serverName = player.getCurrentServer().isPresent()
|
||||
final Player player = (Player) commandSource;
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
final String serverName = player.getCurrentServer().isPresent()
|
||||
? player.getCurrentServer().get().getServerInfo().getName()
|
||||
: "unknown";
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player, command) || Storage.Blacklist.isDisabledServer(serverName))
|
||||
String tmpCommand = StringUtils.getFirstArg(event.getCommand());
|
||||
if (Communicator.get().hasConnectedClients() && Storage.ConfigSections.Settings.AUTO_LOWERCASE_COMMANDS.isCommand(tmpCommand)) {
|
||||
tmpCommand = tmpCommand.toLowerCase();
|
||||
}
|
||||
|
||||
final String command = tmpCommand;
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(sender, command) || Storage.Blacklist.isDisabledServer(serverName))
|
||||
return event;
|
||||
|
||||
final String displayCommand = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
final List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
Storage.ConfigSections.Messages.NOTIFICATION.ALERT,
|
||||
"%player%", player.getUsername(),
|
||||
"%command%", displayCommand,
|
||||
@@ -55,6 +68,8 @@ public class VelocityBlockCommandListener {
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command)) {
|
||||
|
||||
Communicator.Proxy2Backend.sendNotification(player.getUniqueId(), serverName, displayCommand);
|
||||
|
||||
MessageTranslator.send(
|
||||
player,
|
||||
Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE,
|
||||
@@ -77,6 +92,8 @@ public class VelocityBlockCommandListener {
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(command)) {
|
||||
|
||||
Communicator.Proxy2Backend.sendNotification(player.getUniqueId(), serverName, displayCommand);
|
||||
|
||||
MessageTranslator.send(
|
||||
player,
|
||||
Storage.ConfigSections.Settings.CUSTOM_VERSION.MESSAGE,
|
||||
@@ -97,10 +114,28 @@ public class VelocityBlockCommandListener {
|
||||
return event;
|
||||
}
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED)
|
||||
return event;
|
||||
final boolean cancelBlockedCommand = Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED;
|
||||
final List<Group> groups = GroupManager.getPlayerGroups(sender);
|
||||
|
||||
if (!Storage.Blacklist.canPlayerAccessChat(player, command, serverName)) {
|
||||
boolean allowed = Storage.Blacklist.canPlayerAccessChat(sender, groups, command, serverName);
|
||||
boolean blockedNamespace = false;
|
||||
|
||||
|
||||
if (!Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(sender)) {
|
||||
blockedNamespace = cancelBlockedCommand
|
||||
? Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command)
|
||||
: Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesAlwaysBlock(command);
|
||||
|
||||
if (blockedNamespace) allowed = false;
|
||||
}
|
||||
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED && !blockedNamespace) {
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
if (!allowed) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
|
||||
player,
|
||||
event.getCommand(),
|
||||
@@ -113,6 +148,8 @@ public class VelocityBlockCommandListener {
|
||||
if (!executeCommandEvent.doesNotify())
|
||||
return event;
|
||||
|
||||
Communicator.Proxy2Backend.sendNotification(player.getUniqueId(), serverName, displayCommand);
|
||||
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
MessageTranslator.send(consoleSender, notificationMessage);
|
||||
|
||||
@@ -128,9 +165,12 @@ public class VelocityBlockCommandListener {
|
||||
return event;
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getCommand(), false, false);
|
||||
if (executeCommandEvent.isBlocked())
|
||||
|
||||
final ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getCommand(), false, false);
|
||||
|
||||
if (executeCommandEvent.isBlocked()) {
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
+27
-8
@@ -1,6 +1,7 @@
|
||||
package de.rayzs.pat.plugin.listeners.velocity;
|
||||
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.ServerPlayersChangeEvent;
|
||||
@@ -33,8 +34,14 @@ public class VelocityConnectionListener {
|
||||
public void onServerPreConnect(ServerPreConnectEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final CommandSender sender = CommandSenderHandler.from(player);
|
||||
|
||||
sender.updateSenderObject(player);
|
||||
|
||||
if (Storage.ConfigSections.Settings.UPDATE_GROUPS_PER_SERVER.ENABLED) {
|
||||
final ServerInfo serverInfo = event.getOriginalServer().getServerInfo();
|
||||
if (serverInfo != null) Storage.tempCachePlayerToServer(player.getUniqueId(), serverInfo.getName());
|
||||
}
|
||||
|
||||
PATEventHandler.callServerPlayersChangeEvents(player, ServerPlayersChangeEvent.Type.JOINED);
|
||||
|
||||
if(CustomServerBrand.isEnabled())
|
||||
@@ -43,9 +50,8 @@ public class VelocityConnectionListener {
|
||||
}).delay(500, TimeUnit.MILLISECONDS).schedule();
|
||||
|
||||
PermissionUtil.setPlayerPermissions(sender);
|
||||
sender.updateGroups();
|
||||
|
||||
if(Storage.OUTDATED && PermissionUtil.hasPermission(player, "joinupdate")) {
|
||||
if (Storage.OUTDATED && PermissionUtil.hasPermission(sender, "joinupdate")) {
|
||||
server.getScheduler().buildTask(loader, () -> {
|
||||
if (player.isActive())
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.UPDATE.OUTDATED, "%player%", player.getUsername());
|
||||
@@ -55,17 +61,28 @@ public class VelocityConnectionListener {
|
||||
|
||||
@Subscribe
|
||||
public void onServerSwitch(ServerConnectedEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (!VelocityPacketAnalyzer.isInjected(player)) {
|
||||
|
||||
if (!VelocityPacketAnalyzer.inject(player)) {
|
||||
Logger.warning("Attempting delayed injection for " + player.getUsername());
|
||||
server.getScheduler().buildTask(loader, () -> {
|
||||
|
||||
if (!VelocityPacketAnalyzer.inject(player)) {
|
||||
Logger.warning("Second injection for " + player.getUsername() + " failed as well!");
|
||||
player.disconnect(Component.text("Failed to inject player!"));
|
||||
|
||||
if (Storage.ConfigSections.Settings.INJECTION_FAILED.ENABLED) {
|
||||
|
||||
Logger.info(MessageTranslator.replaceMessage(
|
||||
player,
|
||||
Storage.ConfigSections.Settings.INJECTION_FAILED.CONSOLE_MESSAGE
|
||||
));
|
||||
|
||||
player.disconnect(Component.text(
|
||||
MessageTranslator.replaceMessage(
|
||||
player,
|
||||
Storage.ConfigSections.Settings.INJECTION_FAILED.KICK_MESSAGE
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}).delay(1, TimeUnit.SECONDS).schedule();
|
||||
@@ -73,8 +90,10 @@ public class VelocityConnectionListener {
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.UPDATE_GROUPS_PER_SERVER.ENABLED) {
|
||||
CommandSender sender = CommandSenderHandler.from(player);
|
||||
final ServerInfo serverInfo = event.getServer().getServerInfo();
|
||||
if (serverInfo != null) Storage.tempCachePlayerToServer(player.getUniqueId(), serverInfo.getName());
|
||||
|
||||
CommandSender sender = CommandSenderHandler.from(player);
|
||||
assert sender != null;
|
||||
PermissionUtil.reloadPermissions(sender);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ public class Logger {
|
||||
private static final String LOG_HEADER;
|
||||
|
||||
static {
|
||||
final String software = Reflection.isProxyServer()
|
||||
? Reflection.isVelocityServer() ? "Velocity" : "Bungeecord"
|
||||
: (Reflection.isPaper() ? "Paper" : Reflection.isFoliaServer() ? "Folia" : "Spigot/Bukkit");
|
||||
final String software = Reflection.getSoftware().isProxySoftware()
|
||||
? Reflection.getSoftware().toString()
|
||||
: Reflection.getVersionName();
|
||||
|
||||
final String version = Reflection.isProxyServer() ? "" : " " + Reflection.getRawVersionName().replace("_", ".");
|
||||
|
||||
@@ -82,6 +82,12 @@ public class Logger {
|
||||
private static String createInfo() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (!Reflection.isProxyServer()) {
|
||||
builder.append("Detected Software-API: ")
|
||||
.append(Reflection.getSoftware().toString())
|
||||
.append("\n\n");
|
||||
}
|
||||
|
||||
builder.append("Updated: ")
|
||||
.append(!Storage.OUTDATED)
|
||||
.append("\n\n");
|
||||
@@ -90,14 +96,6 @@ public class Logger {
|
||||
.append(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED ? "WHITELIST" : "BLACKLIST")
|
||||
.append("\n");
|
||||
|
||||
builder.append("Detected Software-API: ")
|
||||
.append(Reflection.isProxyServer()
|
||||
? Reflection.isPaper() ? "Waterfall" :
|
||||
Reflection.isVelocityServer() ? "Velocity" : "Bungeecord"
|
||||
: Reflection.isFoliaServer() ? "Folia"
|
||||
: Reflection.isPaper() ? "Paper" : "Spigot")
|
||||
.append("\n");
|
||||
|
||||
builder.append("Installed plugins: \n ")
|
||||
.append(String.join("\n ", Storage.getLoader().getPluginNames("%n (%v)")))
|
||||
.append("\n\n");
|
||||
@@ -129,7 +127,11 @@ public class Logger {
|
||||
.append("\n");
|
||||
|
||||
builder.append("last-received-sync: ")
|
||||
.append(Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED ? Storage.LAST_SYNC : "Deactivated")
|
||||
.append(Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED ? TimeConverter.calcAndGetTime(Communicator.get().getLastSync()) : "Deactivated")
|
||||
.append("\n");
|
||||
|
||||
builder.append("last-received-alive-response-packet: ")
|
||||
.append(Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED ? TimeConverter.calcAndGetTime(Communicator.get().getLastReceivedKeepAliveResponse()) : "Deactivated")
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
@@ -143,13 +145,22 @@ public class Logger {
|
||||
.append("\n");
|
||||
|
||||
builder.append("last-sent-sync: ")
|
||||
.append(Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED ? "Deactivated" : (System.currentTimeMillis() - Storage.LAST_SYNC))
|
||||
.append(Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED ? "Deactivated" : (TimeConverter.calcAndGetTime(Communicator.get().getLastSync())))
|
||||
.append("\n\n");
|
||||
|
||||
for (ClientInfo client : Communicator.CLIENTS) {
|
||||
builder.append("synced-server: ")
|
||||
.append(client.getName() + " (" + client.getSyncTime() + ")")
|
||||
.append(", ");
|
||||
builder.append("synced-server: ");
|
||||
Iterator<ClientInfo> iterator = Communicator.get().getClients().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ClientInfo clientInfo = iterator.next();
|
||||
|
||||
builder.append(clientInfo.getServerName())
|
||||
.append(" (")
|
||||
.append(clientInfo.getFormattedLastReceivedKeepAlivePacketTime() + " / " + clientInfo.getFormattedSyncTime())
|
||||
.append(")");
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("\n\n");
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
package de.rayzs.pat.plugin.modules.events;
|
||||
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import de.rayzs.pat.api.event.events.*;
|
||||
import de.rayzs.pat.utils.subargs.Arguments;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class UpdateList {
|
||||
|
||||
public static UpdatePluginEvent UPDATE_PLUGIN_EVENT = new UpdatePluginEvent() {
|
||||
@Override
|
||||
public void handle(UpdatePluginEvent event) {
|
||||
SubArgsModule.updateMessages();
|
||||
SubArgsModule.updateList();
|
||||
}
|
||||
};
|
||||
|
||||
public static ServerPlayersChangeEvent SERVER_PLAYERS_CHANGE_EVENT = new ServerPlayersChangeEvent() {
|
||||
@Override
|
||||
public void handle(ServerPlayersChangeEvent event) {
|
||||
SubArgsModule.updatePlayerNames();
|
||||
}
|
||||
};
|
||||
|
||||
public static ReceiveSyncEvent RECEIVE_SYNC_EVENT = new ReceiveSyncEvent() {
|
||||
@Override
|
||||
public void handle(ReceiveSyncEvent event) {
|
||||
SubArgsModule.updateList();
|
||||
}
|
||||
};
|
||||
|
||||
public static UpdatePlayerCommandsEvent UPDATE_PLAYER_COMMANDS_EVENT = new UpdatePlayerCommandsEvent() {
|
||||
@Override
|
||||
public void handle(UpdatePlayerCommandsEvent event) {
|
||||
final UUID uuid = event.getSenderObj() instanceof UUID
|
||||
? (UUID) event.getSenderObj()
|
||||
: CommandSenderHandler.from(event.getSenderObj()).getUniqueId();
|
||||
|
||||
final Arguments argument = SubArgsModule.PLAYER_COMMANDS.getOrDefault(uuid, new Arguments());
|
||||
final String serverName = Storage.getLoader().getPlayerServerName(uuid);
|
||||
|
||||
argument.clearArguments();
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
for (String command : event.getCommands())
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
final List<String> chatInputs = new ArrayList<>(argument.CHAT_ARGUMENTS.getGeneralArgument().getInputs());
|
||||
final List<String> tabInput = new ArrayList<>(argument.TAB_ARGUMENTS.getGeneralArgument().getInputs());
|
||||
|
||||
for (String command : chatInputs) {
|
||||
Storage.Blacklist.BlockType type = Storage.Blacklist.BlockTypeFetcher.getType(command);
|
||||
|
||||
if (type != Storage.Blacklist.BlockType.NEGATE)
|
||||
command = Storage.Blacklist.BlockTypeFetcher.modify(command, type);
|
||||
|
||||
argument.CHAT_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
}
|
||||
|
||||
for (String command : tabInput) {
|
||||
Storage.Blacklist.BlockType type = Storage.Blacklist.BlockTypeFetcher.getType(command);
|
||||
|
||||
if (type != Storage.Blacklist.BlockType.NEGATE)
|
||||
command = Storage.Blacklist.BlockTypeFetcher.modify(command, type);
|
||||
|
||||
argument.TAB_ARGUMENTS.buildArguments(command);
|
||||
}
|
||||
|
||||
for (String command : SubArgsModule.getGroupCommands(uuid, serverName))
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
for (String command : SubArgsModule.getServerCommands(uuid))
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
} else {
|
||||
List<String> groupCommands = SubArgsModule.getGroupCommands(uuid, serverName);
|
||||
|
||||
for (String command : argument.CHAT_ARGUMENTS.getGeneralArgument().getInputs()) {
|
||||
if (groupCommands.contains(command)) continue;
|
||||
|
||||
argument.CHAT_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
}
|
||||
|
||||
for (String command : argument.TAB_ARGUMENTS.getGeneralArgument().getInputs()) {
|
||||
if (groupCommands.contains(command)) continue;
|
||||
|
||||
argument.TAB_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
}
|
||||
}
|
||||
|
||||
SubArgsModule.PLAYER_COMMANDS.putIfAbsent(uuid, argument);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.info;
|
||||
|
||||
import de.rayzs.pat.api.communication.BackendUpdater;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
@@ -22,17 +23,33 @@ public class InfoCommand extends ProCommand {
|
||||
|
||||
String message = StringUtils.getStringList(Storage.ConfigSections.Messages.INFO.MESSAGE.getLines(), "\n");
|
||||
|
||||
String syncTime = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED || Reflection.isProxyServer()
|
||||
? Storage.ConfigSections.Messages.INFO.SYNC_TIME.replace("%time%", TimeConverter.calcAndGetTime(Reflection.isProxyServer()
|
||||
? Communicator.LAST_DATA_UPDATE : Communicator.LAST_BUKKIT_SYNC))
|
||||
String syncTime = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED ||
|
||||
Reflection.isProxyServer()
|
||||
? Storage.ConfigSections.Messages.INFO.SYNC_TIME.replace("%time%", TimeConverter.calcAndGetTime(Communicator.get().getLastSync()))
|
||||
: Storage.ConfigSections.Messages.INFO.SYNC_DISABLED;
|
||||
|
||||
String versionStatus = Storage.OUTDATED
|
||||
String lastAlivePacketTime = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED ||
|
||||
Reflection.isProxyServer()
|
||||
? Storage.ConfigSections.Messages.INFO.SYNC_TIME.replace("%time%", TimeConverter.calcAndGetTime(Communicator.get().getLastReceivedKeepAliveResponse()))
|
||||
: Storage.ConfigSections.Messages.INFO.SYNC_DISABLED;
|
||||
|
||||
|
||||
if (!Reflection.isProxyServer()
|
||||
&& !BackendUpdater.isConnected()
|
||||
&& Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED)
|
||||
{
|
||||
syncTime = Storage.ConfigSections.Messages.INFO.SYNC_WAITING;
|
||||
lastAlivePacketTime = Storage.ConfigSections.Messages.INFO.SYNC_WAITING;
|
||||
}
|
||||
|
||||
|
||||
final String versionStatus = Storage.OUTDATED
|
||||
? Storage.ConfigSections.Messages.INFO.VERSION_OUTDATED
|
||||
: Storage.ConfigSections.Messages.INFO.VERSION_UPDATED;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%sync_time%", syncTime,
|
||||
"%last_alive_response%", lastAlivePacketTime,
|
||||
"%version_status%", versionStatus
|
||||
);
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class StatsCommand extends ProCommand {
|
||||
|
||||
@@ -29,26 +31,28 @@ public class StatsCommand extends ProCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
final int length = Communicator.CLIENTS.size() - 1;
|
||||
boolean tmpFound = false;
|
||||
final Set<ClientInfo> clients = Communicator.get().getClients();
|
||||
final Iterator<ClientInfo> iterator = clients.iterator();
|
||||
|
||||
boolean tmpFound = false;
|
||||
StringBuilder statsBuilder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < Communicator.CLIENTS.size(); i++) {
|
||||
ClientInfo client = Communicator.CLIENTS.get(i);
|
||||
while (iterator.hasNext()) {
|
||||
ClientInfo client = iterator.next();
|
||||
|
||||
if (!client.hasSentFeedback())
|
||||
continue;
|
||||
|
||||
if (!tmpFound)
|
||||
if (!tmpFound) {
|
||||
tmpFound = true;
|
||||
}
|
||||
|
||||
statsBuilder.append(StringUtils.replace(Storage.ConfigSections.Messages.STATS.SERVER,
|
||||
"%updated%", client.getSyncTime(), "%servername%", client.getName()
|
||||
"%updated%", client.getFormattedSyncTime(),
|
||||
"%servername%", client.getServerName(),
|
||||
"%last_alive_response%", client.getFormattedLastReceivedKeepAlivePacketTime()
|
||||
));
|
||||
|
||||
if (i <= length)
|
||||
if (iterator.hasNext()) {
|
||||
statsBuilder.append(Storage.ConfigSections.Messages.STATS.SPLITTER);
|
||||
}
|
||||
}
|
||||
|
||||
final boolean found = tmpFound;
|
||||
@@ -56,8 +60,9 @@ public class StatsCommand extends ProCommand {
|
||||
Storage.ConfigSections.Messages.STATS.STATISTIC.getLines().forEach(message -> {
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%server_count%", String.valueOf(Communicator.SERVER_DATA_SYNC_COUNT),
|
||||
"%last_sync_time%", TimeConverter.calcAndGetTime(Communicator.LAST_DATA_UPDATE),
|
||||
"%server_count%", String.valueOf(Communicator.get().getClients().size()),
|
||||
"%last_sync_time%", TimeConverter.calcAndGetTime(Communicator.get().getLastSync()),
|
||||
"%last_alive_response_time%", TimeConverter.calcAndGetTime(Communicator.get().getLastReceivedKeepAliveResponse()),
|
||||
"%servers%", found ? statsBuilder.toString() : Storage.ConfigSections.Messages.STATS.NO_SERVER
|
||||
);
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ public class AddCommand extends ProCommand {
|
||||
if (command.isEmpty())
|
||||
return false;
|
||||
|
||||
final boolean loadBlacklist = command.startsWith("plugin=") || command.startsWith("!");
|
||||
final int length = args.length;
|
||||
|
||||
if (length == 1) {
|
||||
@@ -67,6 +68,8 @@ public class AddCommand extends ProCommand {
|
||||
|
||||
if (!exist) {
|
||||
Storage.Blacklist.getBlacklist().add(command).save();
|
||||
if (loadBlacklist) Storage.Blacklist.getBlacklist().load();
|
||||
|
||||
Storage.handleChange();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ public class ClearCommand extends ProCommand {
|
||||
}
|
||||
|
||||
Storage.Blacklist.getBlacklist().clear().save();
|
||||
Storage.Blacklist.getBlacklist().load();
|
||||
Storage.handleChange();
|
||||
|
||||
CONFIRMATION.remove(sender.getUniqueId());
|
||||
|
||||
@@ -3,18 +3,10 @@ package de.rayzs.pat.plugin.process.impl.local.modify;
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.BlacklistStorage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.plugin.converter.Converter;
|
||||
import de.rayzs.pat.plugin.converter.StorageConverter;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ExtractCommand extends ProCommand {
|
||||
@@ -26,6 +18,37 @@ public class ExtractCommand extends ProCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private enum Mode {
|
||||
|
||||
BOTH("both", true), ONLY_COLON("only-colon", true), NON_COLON("non-colon", false);
|
||||
|
||||
private static Mode getMode(final String name) {
|
||||
for (final Mode mode : Mode.values()) {
|
||||
if (mode.getName().equalsIgnoreCase(name)) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean doesIncludesColons() {
|
||||
return includesColons;
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final boolean includesColons;
|
||||
|
||||
Mode(final String name, final boolean includesColons) {
|
||||
this.name = name;
|
||||
this.includesColons = includesColons;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
@@ -34,40 +57,29 @@ public class ExtractCommand extends ProCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
Mode mode = Mode.NON_COLON;
|
||||
|
||||
String pluginName = args[0].toLowerCase();
|
||||
boolean failed = false, useColons = false;
|
||||
boolean failed = false;
|
||||
Group group = null;
|
||||
|
||||
|
||||
if (args.length == 2) {
|
||||
|
||||
group = GroupManager.getGroupByName(args[1]);
|
||||
|
||||
if (group == null) {
|
||||
useColons = Boolean.parseBoolean(args[1]);
|
||||
|
||||
if (!useColons && !args[1].equalsIgnoreCase("false")) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
useColons = Boolean.parseBoolean(args[1]);
|
||||
} catch (Exception exception) {
|
||||
group = GroupManager.getGroupByName(args[1]);
|
||||
failed = group == null;
|
||||
mode = Mode.getMode(args[1]);
|
||||
failed = mode == null;
|
||||
}
|
||||
|
||||
} else if (args.length == 3) {
|
||||
group = GroupManager.getGroupByName(args[1]);
|
||||
|
||||
if (group == null) {
|
||||
group = GroupManager.getGroupByName(args[1]);
|
||||
mode = Mode.getMode(args[2]);
|
||||
|
||||
if (group == null || mode == null) {
|
||||
failed = true;
|
||||
} else {
|
||||
try {
|
||||
useColons = Boolean.parseBoolean(args[2]);
|
||||
} catch (Exception exception) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +89,7 @@ public class ExtractCommand extends ProCommand {
|
||||
}
|
||||
|
||||
List<String> pluginNames = Storage.getLoader().getPluginNames("%n");
|
||||
boolean pluginFound = false;
|
||||
boolean pluginFound = false, all = pluginName.equalsIgnoreCase("*");
|
||||
|
||||
for (String name : pluginNames) {
|
||||
if (name.equalsIgnoreCase(pluginName)) {
|
||||
@@ -86,7 +98,7 @@ public class ExtractCommand extends ProCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if (!pluginFound) {
|
||||
if (!all && !pluginFound) {
|
||||
sender.sendMessage(StringUtils.replace(Storage.ConfigSections.Messages.EXTRACT.PLUGIN_NOT_FOUND,
|
||||
"%plugin%", pluginName)
|
||||
);
|
||||
@@ -94,16 +106,12 @@ public class ExtractCommand extends ProCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> commands = new ArrayList<>();
|
||||
for (Map.Entry<String, Command> entry : BukkitLoader.getCommandsMap().entrySet()) {
|
||||
if (entry.getKey().toLowerCase().startsWith(pluginName + ":")) {
|
||||
String command = entry.getKey().substring(args[0].length() + 1);
|
||||
commands.add(command);
|
||||
List<String> commands = all
|
||||
? Storage.getLoader().getAllCommands(mode.doesIncludesColons())
|
||||
: Storage.getLoader().getPluginCommands(args[0], mode.doesIncludesColons());
|
||||
|
||||
if (useColons) {
|
||||
commands.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
if (mode == Mode.ONLY_COLON) {
|
||||
commands = commands.stream().filter(command -> command.contains(":")).toList();
|
||||
}
|
||||
|
||||
BlacklistStorage storage = group == null
|
||||
@@ -128,14 +136,16 @@ public class ExtractCommand extends ProCommand {
|
||||
final int length = args.length;
|
||||
|
||||
if (length <= 1) {
|
||||
return Storage.getLoader().getPluginNames("%n");
|
||||
final List<String> suggestions = Storage.getLoader().getPluginNames("%n");
|
||||
suggestions.add("*");
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
if (length == 2 || length == 3 && GroupManager.getGroupByName(args[1]) != null) {
|
||||
result.add("true");
|
||||
result.add("false");
|
||||
result.addAll(Arrays.stream(Mode.values()).map(Mode::getName).toList());
|
||||
}
|
||||
|
||||
if (length == 2) {
|
||||
|
||||
@@ -57,6 +57,7 @@ public class RemoveCommand extends ProCommand {
|
||||
if (command.isEmpty())
|
||||
return false;
|
||||
|
||||
final boolean loadBlacklist = command.startsWith("plugin=") || command.startsWith("!");
|
||||
final int length = args.length;
|
||||
|
||||
if (length == 1) {
|
||||
@@ -64,6 +65,8 @@ public class RemoveCommand extends ProCommand {
|
||||
|
||||
if (exist) {
|
||||
Storage.Blacklist.getBlacklist().remove(command).save();
|
||||
if (loadBlacklist) Storage.Blacklist.getBlacklist().load();
|
||||
|
||||
Storage.handleChange();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,20 +18,20 @@ public class NotifyCommand extends ProCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if (backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean enabled = false;
|
||||
boolean enabled;
|
||||
|
||||
if (sender.isConsole()) {
|
||||
enabled = Storage.SEND_CONSOLE_NOTIFICATION;
|
||||
Storage.SEND_CONSOLE_NOTIFICATION = !Storage.SEND_CONSOLE_NOTIFICATION;
|
||||
} else {
|
||||
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if (backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
enabled = Storage.NOTIFY_PLAYERS.contains(sender.getUniqueId());
|
||||
|
||||
if (enabled)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.system;
|
||||
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.BukkitAntiTabListener;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
@@ -22,8 +23,6 @@ public class UpdateCommand extends ProCommand {
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
PermissionUtil.reloadPermissions();
|
||||
|
||||
Storage.getLoader().getOnlinePlayerNames().forEach(name -> {
|
||||
Object playerObj = Storage.getLoader().getPlayerObjByName(name);
|
||||
|
||||
@@ -35,8 +34,10 @@ public class UpdateCommand extends ProCommand {
|
||||
}
|
||||
});
|
||||
|
||||
if (!Reflection.isProxyServer() && Reflection.getMinor() >= 13) {
|
||||
if (!Reflection.isProxyServer() && Reflection.isAtLeast(1, 13)) {
|
||||
BukkitAntiTabListener.handleTabCompletion();
|
||||
} else if (Reflection.isProxyServer()) {
|
||||
Communicator.Proxy2Backend.sendUpdateCommand();
|
||||
}
|
||||
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.UPDATE_PERMISSIONS.UPDATE_ALL);
|
||||
@@ -64,8 +65,10 @@ public class UpdateCommand extends ProCommand {
|
||||
|
||||
PermissionUtil.reloadPermissions(targetSender);
|
||||
|
||||
if (!Reflection.isProxyServer() && Reflection.getMinor() >= 13) {
|
||||
if (!Reflection.isProxyServer() && Reflection.isAtLeast(1, 13)) {
|
||||
BukkitAntiTabListener.handleTabCompletion(uuid);
|
||||
} else if (Reflection.isProxyServer()) {
|
||||
Communicator.Proxy2Backend.sendUpdateCommand(uuid, targetSender.getServerName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -90,7 +90,15 @@ public class ServAddCommand extends ProCommand {
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER.replace("%group%", groupName));
|
||||
|
||||
String message = Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%group%", groupName,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.rayzs.pat.plugin.process.impl.server;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
@@ -66,12 +67,14 @@ public class ServClearCommand extends ProCommand {
|
||||
|
||||
if (group == null) {
|
||||
|
||||
sender.sendMessage(
|
||||
Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER
|
||||
.replace("%group%", groupName)
|
||||
.replace("%server%", serverName)
|
||||
String message = Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%group%", groupName,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,12 +95,14 @@ public class ServRemoveCommand extends ProCommand {
|
||||
|
||||
if (group == null) {
|
||||
|
||||
sender.sendMessage(
|
||||
Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER
|
||||
.replace("%group%", groupName)
|
||||
.replace("%server%", serverName)
|
||||
String message = Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%group%", groupName,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ public class ServListCommand extends ProCommand {
|
||||
);
|
||||
|
||||
String message = Storage.ConfigSections.Messages.BLACKLIST.LIST_SERVER_MESSAGE;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%size%", String.valueOf(blacklist.getCommands().size()),
|
||||
"%commands%", commandsListMessage,
|
||||
@@ -57,7 +58,15 @@ public class ServListCommand extends ProCommand {
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER.replace("%group%", groupName));
|
||||
|
||||
String message = Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%group%", groupName,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+114
-22
@@ -1,10 +1,11 @@
|
||||
package de.rayzs.pat.plugin.modules;
|
||||
package de.rayzs.pat.plugin.subarguments;
|
||||
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.plugin.modules.events.ExecuteCommand;
|
||||
import de.rayzs.pat.plugin.modules.events.TabCompletion;
|
||||
import de.rayzs.pat.plugin.modules.events.UpdateList;
|
||||
import de.rayzs.pat.utils.node.CommandNodeHelper;
|
||||
import de.rayzs.pat.plugin.subarguments.events.ExecuteCommand;
|
||||
import de.rayzs.pat.plugin.subarguments.events.TabCompletion;
|
||||
import de.rayzs.pat.plugin.subarguments.events.UpdateList;
|
||||
import de.rayzs.pat.utils.node.BukkitCommandNodeHelper;
|
||||
import de.rayzs.pat.utils.node.ProxyCommandNodeHelper;
|
||||
import de.rayzs.pat.utils.permission.PermissionPlugin;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
@@ -17,7 +18,7 @@ import de.rayzs.pat.utils.group.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class SubArgsModule {
|
||||
public class SubArguments {
|
||||
|
||||
public static List<String> GENERAL_LIST, BLOCKED_MESSAGE, PLAYER_NAMES, ONLINE_PLAYERS;
|
||||
public static HashMap<UUID, Arguments> PLAYER_COMMANDS = new HashMap<>();
|
||||
@@ -55,7 +56,7 @@ public class SubArgsModule {
|
||||
Arguments.ARGUMENTS.clearArguments();
|
||||
|
||||
GENERAL_LIST.forEach(command -> Arguments.ARGUMENTS.buildArgumentStacks(command));
|
||||
SubArgsModule.PLAYER_COMMANDS = new HashMap<>();
|
||||
SubArguments.PLAYER_COMMANDS = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void updateMessages() {
|
||||
@@ -63,9 +64,8 @@ public class SubArgsModule {
|
||||
ResponseHandler.update();
|
||||
}
|
||||
|
||||
public static void handleCommandNode(UUID uuid, CommandNodeHelper helper) {
|
||||
if (!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return;
|
||||
public static void handleCommandNode(UUID uuid, ProxyCommandNodeHelper helper) {
|
||||
final boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
|
||||
Arguments arguments = PLAYER_COMMANDS.get(uuid);
|
||||
if (arguments == null) {
|
||||
@@ -73,13 +73,104 @@ public class SubArgsModule {
|
||||
}
|
||||
|
||||
ArgumentSource source = arguments.TAB_ARGUMENTS;
|
||||
if (source == null) return;
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> inputs = source.getAllInputs();
|
||||
List<String> allEntries = inputs.stream().map(StringUtils::getFirstArg).toList();
|
||||
final List<String> inputs = source.getAllInputs();
|
||||
final List<String> actuallyExistingCommands = helper.getChildrenNames();
|
||||
|
||||
helper.removeIf(allEntries::contains);
|
||||
inputs.forEach(input -> helper.add(input, true));
|
||||
if (turn) {
|
||||
List<String> allEntries = inputs.stream().map(StringUtils::getFirstArg).toList();
|
||||
helper.removeIf(allEntries::contains);
|
||||
}
|
||||
|
||||
final int length = inputs.size();
|
||||
for (int i = 0; i < length; i++) {
|
||||
String input;
|
||||
|
||||
try {
|
||||
input = inputs.get(i);
|
||||
} catch (IndexOutOfBoundsException indexOutOfBoundsException) {
|
||||
break;
|
||||
}
|
||||
|
||||
final boolean negated = Storage.Blacklist.BlockTypeFetcher.isNegated(input);
|
||||
|
||||
if (!negated) {
|
||||
|
||||
if (turn && actuallyExistingCommands.contains(StringUtils.getFirstArg(input))) {
|
||||
helper.add(input, true);
|
||||
} else helper.removeSubArguments(input);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
final Storage.Blacklist.BlockType type = Storage.Blacklist.BlockTypeFetcher.getType(input);
|
||||
if (type == Storage.Blacklist.BlockType.CHAT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
input = Storage.Blacklist.BlockTypeFetcher.cleanse(input);
|
||||
|
||||
if (turn) helper.removeSubArguments(input);
|
||||
else if (actuallyExistingCommands.contains(StringUtils.getFirstArg(input))) {
|
||||
helper.add(input, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleCommandNode(UUID uuid, BukkitCommandNodeHelper helper) throws Exception {
|
||||
final boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
|
||||
Arguments arguments = PLAYER_COMMANDS.get(uuid);
|
||||
if (arguments == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArgumentSource source = arguments.TAB_ARGUMENTS;
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<String> inputs = new ArrayList<>(source.getAllInputs());
|
||||
final List<String> argumentsList = new ArrayList<>();
|
||||
|
||||
final int length = inputs.size();
|
||||
for (int i = 0; i < length; i++) {
|
||||
String input;
|
||||
|
||||
try {
|
||||
input = inputs.get(i);
|
||||
} catch (IndexOutOfBoundsException indexOutOfBoundsException) {
|
||||
break;
|
||||
}
|
||||
|
||||
final Storage.Blacklist.BlockType type = Storage.Blacklist.BlockTypeFetcher.getType(input);
|
||||
if (type == Storage.Blacklist.BlockType.CHAT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final boolean negated = Storage.Blacklist.BlockTypeFetcher.isNegated(input);
|
||||
input = Storage.Blacklist.BlockTypeFetcher.cleanse(input);
|
||||
|
||||
if (!negated) {
|
||||
|
||||
if (turn) argumentsList.add(input);
|
||||
else helper.removeSubArguments(input);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (turn) helper.removeSubArguments(input);
|
||||
else argumentsList.add(input);
|
||||
}
|
||||
|
||||
if (argumentsList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
helper.spareRecursively(argumentsList);
|
||||
}
|
||||
|
||||
public static List<String> getServerCommands(UUID uuid) {
|
||||
@@ -110,7 +201,7 @@ public class SubArgsModule {
|
||||
List<Group> groups;
|
||||
|
||||
if (Storage.getPermissionPlugin() == PermissionPlugin.NONE) {
|
||||
CommandSender sender = CommandSenderHandler.getSenderFromUUID(uuid);
|
||||
CommandSender sender = CommandSenderHandler.from(uuid);
|
||||
groups = GroupManager.getPlayerGroups(sender);
|
||||
} else {
|
||||
groups = GroupManager.getPlayerGroups(uuid);
|
||||
@@ -145,11 +236,6 @@ public class SubArgsModule {
|
||||
online = Storage.getLoader().isPlayerOnline(s),
|
||||
general = Storage.getLoader().doesPlayerExist(s);
|
||||
|
||||
if (number) {
|
||||
split[i] = "%numbers%";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (online && general) {
|
||||
split[i] = "%both_players%";
|
||||
continue;
|
||||
@@ -160,8 +246,14 @@ public class SubArgsModule {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (general)
|
||||
if (general) {
|
||||
split[i] = "%players%";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (number) {
|
||||
split[i] = "%numbers%";
|
||||
}
|
||||
}
|
||||
|
||||
return String.join(" ", split);
|
||||
+26
-6
@@ -1,7 +1,7 @@
|
||||
package de.rayzs.pat.plugin.modules.events;
|
||||
package de.rayzs.pat.plugin.subarguments.events;
|
||||
|
||||
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
@@ -34,13 +34,15 @@ public class ExecuteCommand extends ExecuteCommandEvent {
|
||||
return;
|
||||
|
||||
UUID uuid = sender.getUniqueId();
|
||||
String serverName = sender.getServerName();
|
||||
String playerName = sender.getName();
|
||||
|
||||
if (isBlocked(sender, command)) {
|
||||
event.setBlocked(true);
|
||||
event.setCancelled(true);
|
||||
|
||||
MessageTranslator.send(event.getSenderObj(),
|
||||
ResponseHandler.getResponse(uuid, event.getCommand()),
|
||||
ResponseHandler.getResponse(uuid, playerName, serverName, event.getCommand()),
|
||||
"%command%", displayCommand);
|
||||
|
||||
return;
|
||||
@@ -53,14 +55,14 @@ public class ExecuteCommand extends ExecuteCommandEvent {
|
||||
|
||||
MessageTranslator.send(
|
||||
event.getSenderObj(),
|
||||
ResponseHandler.getResponse(uuid, event.getCommand(), Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE.getLines()),
|
||||
ResponseHandler.getResponse(uuid, playerName, serverName, event.getCommand(), Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE.getLines()),
|
||||
"%command%", StringUtils.getFirstArg(displayCommand)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private boolean isBlocked(CommandSender sender, String command) {
|
||||
final Arguments arguments = SubArgsModule.PLAYER_COMMANDS.getOrDefault(sender.getUniqueId(), Arguments.ARGUMENTS);
|
||||
final Arguments arguments = SubArguments.PLAYER_COMMANDS.getOrDefault(sender.getUniqueId(), Arguments.ARGUMENTS);
|
||||
final List<String> commands = new ArrayList<>(arguments.CHAT_ARGUMENTS.getGeneralArgument().getInputs());
|
||||
final String firstArgument = StringUtils.getFirstArg(command);
|
||||
|
||||
@@ -119,7 +121,7 @@ public class ExecuteCommand extends ExecuteCommandEvent {
|
||||
).toList();
|
||||
|
||||
if (!placeholderCommands.isEmpty()) {
|
||||
command = SubArgsModule.replacePlaceholders(command);
|
||||
command = SubArguments.replacePlaceholders(command);
|
||||
}
|
||||
|
||||
String cpyCommand;
|
||||
@@ -136,6 +138,24 @@ public class ExecuteCommand extends ExecuteCommandEvent {
|
||||
cpyCommand = StringUtils.replace(command, "%both_players%", "%players%");
|
||||
}
|
||||
|
||||
if (c.contains("%offline_players%")) {
|
||||
|
||||
final String[] cSplit = c.split(" ");
|
||||
final String[] cpyCommandSplit = cpyCommand.split(" ");
|
||||
|
||||
for (int i = 0; i < cSplit.length; i++) {
|
||||
if (i >= cpyCommandSplit.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (cSplit[i].equals("%offline_players%") && !cpyCommandSplit[i].endsWith("players%")) {
|
||||
cpyCommandSplit[i] = "%offline_players%";
|
||||
}
|
||||
}
|
||||
|
||||
cpyCommand = String.join(" ", cpyCommandSplit);
|
||||
}
|
||||
|
||||
boolean ends = c.endsWith("_-");
|
||||
if (ends) {
|
||||
c = StringUtils.replace(c, "_-", "");
|
||||
+24
-10
@@ -1,7 +1,7 @@
|
||||
package de.rayzs.pat.plugin.modules.events;
|
||||
package de.rayzs.pat.plugin.subarguments.events;
|
||||
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
@@ -17,12 +17,18 @@ public class TabCompletion extends FilteredTabCompletionEvent {
|
||||
|
||||
if (event.getCompletion().isEmpty()) return;
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(cursor) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(cursor)) {
|
||||
event.setCompletion(List.of());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
final UUID uuid = event.getSenderObj() instanceof UUID
|
||||
? (UUID) event.getSenderObj()
|
||||
: CommandSenderHandler.from(event.getSenderObj()).getUniqueId();
|
||||
|
||||
final Arguments arguments = SubArgsModule.PLAYER_COMMANDS.getOrDefault(uuid, Arguments.ARGUMENTS);
|
||||
final Arguments arguments = SubArguments.PLAYER_COMMANDS.getOrDefault(uuid, Arguments.ARGUMENTS);
|
||||
|
||||
List<String> possibilities = event.getCompletion(), result = new ArrayList<>(arguments.getResultTab(cursor));
|
||||
final List<String> negated = new ArrayList<>(arguments.getResultTab("!" + cursor));
|
||||
@@ -67,19 +73,24 @@ public class TabCompletion extends FilteredTabCompletionEvent {
|
||||
|
||||
if (result.contains("%players%")) {
|
||||
possibilities.remove("%players%");
|
||||
possibilities.addAll(SubArgsModule.getPlayerNames());
|
||||
possibilities.addAll(SubArguments.getPlayerNames());
|
||||
}
|
||||
|
||||
if (result.contains("%online_players%")) {
|
||||
possibilities.remove("%online_players%");
|
||||
possibilities.addAll(SubArgsModule.getOnlinePlayerNames());
|
||||
possibilities.addAll(SubArguments.getOnlinePlayerNames());
|
||||
}
|
||||
|
||||
if (result.contains("%offline_players%")) {
|
||||
possibilities.remove("%offline_players%");
|
||||
possibilities.removeAll(SubArguments.getOnlinePlayerNames());
|
||||
}
|
||||
|
||||
if (result.contains("%hidden_players%")) {
|
||||
possibilities.remove("%hidden_players%");
|
||||
|
||||
possibilities.addAll(event.getCompletion().stream().filter(completion -> {
|
||||
if (SubArgsModule.getPlayerNames().contains(completion))
|
||||
if (SubArguments.getPlayerNames().contains(completion))
|
||||
return false;
|
||||
|
||||
return result.contains(completion);
|
||||
@@ -94,7 +105,7 @@ public class TabCompletion extends FilteredTabCompletionEvent {
|
||||
possibilities.remove("%hidden_online_players%");
|
||||
|
||||
possibilities.addAll(event.getCompletion().stream().filter(completion -> {
|
||||
if (SubArgsModule.getOnlinePlayerNames().contains(completion))
|
||||
if (SubArguments.getOnlinePlayerNames().contains(completion))
|
||||
return false;
|
||||
|
||||
return result.contains(completion);
|
||||
@@ -109,10 +120,13 @@ public class TabCompletion extends FilteredTabCompletionEvent {
|
||||
possibilities.removeIf(NumberUtils::isDigit);
|
||||
|
||||
if (result.contains("%players%"))
|
||||
possibilities.removeIf(possibility -> SubArgsModule.getPlayerNames().contains(possibility));
|
||||
possibilities.removeIf(possibility -> SubArguments.getPlayerNames().contains(possibility));
|
||||
|
||||
if (result.contains("%offline_players%"))
|
||||
possibilities.removeIf(possibility -> !SubArguments.getPlayerNames().contains(possibility));
|
||||
|
||||
if (result.contains("%online_players%"))
|
||||
possibilities.removeIf(possibility -> SubArgsModule.getOnlinePlayerNames().contains(possibility));
|
||||
possibilities.removeIf(possibility -> SubArguments.getOnlinePlayerNames().contains(possibility));
|
||||
|
||||
|
||||
possibilities.removeIf(s -> {
|
||||
@@ -125,7 +139,7 @@ public class TabCompletion extends FilteredTabCompletionEvent {
|
||||
}
|
||||
|
||||
String firstCursorArg = StringUtils.getFirstArg(cursor.toLowerCase());
|
||||
if (possibilities.isEmpty() && !SubArgsModule.GENERAL_LIST.contains(firstCursorArg)) {
|
||||
if (possibilities.isEmpty() && !SubArguments.GENERAL_LIST.contains(firstCursorArg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package de.rayzs.pat.plugin.subarguments.events;
|
||||
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import de.rayzs.pat.api.event.events.*;
|
||||
import de.rayzs.pat.utils.subargs.Arguments;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class UpdateList {
|
||||
|
||||
public static UpdatePluginEvent UPDATE_PLUGIN_EVENT = new UpdatePluginEvent() {
|
||||
@Override
|
||||
public void handle(UpdatePluginEvent event) {
|
||||
SubArguments.updateMessages();
|
||||
SubArguments.updateList();
|
||||
}
|
||||
};
|
||||
|
||||
public static ServerPlayersChangeEvent SERVER_PLAYERS_CHANGE_EVENT = new ServerPlayersChangeEvent() {
|
||||
@Override
|
||||
public void handle(ServerPlayersChangeEvent event) {
|
||||
SubArguments.updatePlayerNames();
|
||||
}
|
||||
};
|
||||
|
||||
public static ReceiveSyncEvent RECEIVE_SYNC_EVENT = new ReceiveSyncEvent() {
|
||||
@Override
|
||||
public void handle(ReceiveSyncEvent event) {
|
||||
SubArguments.updateList();
|
||||
}
|
||||
};
|
||||
|
||||
public static UpdatePlayerCommandsEvent UPDATE_PLAYER_COMMANDS_EVENT = new UpdatePlayerCommandsEvent() {
|
||||
@Override
|
||||
public void handle(UpdatePlayerCommandsEvent event) {
|
||||
final UUID uuid = event.getSenderObj() instanceof UUID
|
||||
? (UUID) event.getSenderObj()
|
||||
: CommandSenderHandler.from(event.getSenderObj()).getUniqueId();
|
||||
|
||||
final Arguments argument = SubArguments.PLAYER_COMMANDS.getOrDefault(uuid, new Arguments());
|
||||
final String serverName = Storage.getLoader().getPlayerServerName(uuid);
|
||||
|
||||
argument.clearArguments();
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
for (String command : event.getCommands()) {
|
||||
argument.buildArgumentStacks(command);
|
||||
}
|
||||
|
||||
for (String command : SubArguments.getGroupCommands(uuid, serverName)) {
|
||||
argument.buildArgumentStacks(command);
|
||||
}
|
||||
|
||||
for (String command : SubArguments.getServerCommands(uuid)) {
|
||||
argument.buildArgumentStacks(command);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
final List<String> groupCommands = SubArguments.getGroupCommands(uuid, serverName);
|
||||
|
||||
if (Reflection.isProxyServer()) {
|
||||
|
||||
final List<String> commands = SubArguments.getServerCommands(uuid);
|
||||
commands.removeIf(groupCommands::contains);
|
||||
|
||||
for (String command : commands) {
|
||||
argument.buildArgumentStacks(command);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (String command : Arguments.ARGUMENTS.CHAT_ARGUMENTS.getGeneralArgument().getInputs()) {
|
||||
if (groupCommands.contains(command)) continue;
|
||||
|
||||
argument.CHAT_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
}
|
||||
|
||||
for (String command : Arguments.ARGUMENTS.TAB_ARGUMENTS.getGeneralArgument().getInputs()) {
|
||||
if (groupCommands.contains(command)) continue;
|
||||
|
||||
argument.TAB_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SubArguments.PLAYER_COMMANDS.putIfAbsent(uuid, argument);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -5,10 +5,20 @@ import java.util.*;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
public class CommandsCache {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* RECODE PLANNED
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
private List<String> filteredCommands = null, allCommands = null;
|
||||
private boolean change = false;
|
||||
|
||||
@@ -46,7 +56,7 @@ public class CommandsCache {
|
||||
return;
|
||||
|
||||
LinkedList<String> tmpFilteredCommands = new LinkedList<>();
|
||||
List<String> tmpAllCommands = Collections.unmodifiableList(commands);
|
||||
List<String> tmpAllCommands = new ArrayList<>(commands);
|
||||
allCommands = tmpAllCommands;
|
||||
|
||||
final int length = allCommands.size();
|
||||
@@ -72,11 +82,11 @@ public class CommandsCache {
|
||||
filteredCommands = tmpFilteredCommands;
|
||||
}
|
||||
|
||||
public List<String> getPlayerCommands(Collection<String> unfilteredCommands, Object targetObj) {
|
||||
return getPlayerCommands(unfilteredCommands, targetObj, null);
|
||||
public List<String> getPlayerCommands(Collection<String> unfilteredCommands, CommandSender sender, List<Group> groups) {
|
||||
return getPlayerCommands(unfilteredCommands, sender, groups, null);
|
||||
}
|
||||
|
||||
public List<String> getPlayerCommands(Collection<String> unfilteredCommands, Object targetObj, String serverName) {
|
||||
public List<String> getPlayerCommands(Collection<String> unfilteredCommands, CommandSender sender, List<Group> groups, String serverName) {
|
||||
List<String> playerCommands = new LinkedList<>(unfilteredCommands);
|
||||
List<String> localFilteredCommands = filteredCommands == null ? null : new LinkedList<>();
|
||||
|
||||
@@ -96,8 +106,8 @@ public class CommandsCache {
|
||||
}
|
||||
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(targetObj)) {
|
||||
boolean hasNamespaceBypass = Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(targetObj);
|
||||
if (!PermissionUtil.hasBypassPermission(sender)) {
|
||||
boolean hasNamespaceBypass = Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(sender);
|
||||
|
||||
playerCommands.removeIf(command -> {
|
||||
if (!hasNamespaceBypass && Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command)) {
|
||||
@@ -108,12 +118,12 @@ public class CommandsCache {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !Storage.Blacklist.canPlayerAccessTab(targetObj, command, serverName);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(sender, groups, command, serverName);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(targetObj, playerCommands, serverName != null);
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(sender, playerCommands, serverName != null);
|
||||
|
||||
return playerCommands.stream().map(command -> {
|
||||
command = StringUtils.getFirstArg(command);
|
||||
@@ -137,7 +147,7 @@ public class CommandsCache {
|
||||
|
||||
public void reset() {
|
||||
// Removed to reset the change state. Experimental change though
|
||||
//if(change) return;
|
||||
// if(change) return;
|
||||
// Prob. gonna change it to: if (CONNECTED_TO_BUNGEE && change) return;
|
||||
updateChangeState();
|
||||
filteredCommands = null;
|
||||
|
||||
@@ -1,296 +1,194 @@
|
||||
package de.rayzs.pat.utils;
|
||||
|
||||
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
|
||||
import de.rayzs.pat.utils.group.TinyGroup;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class CommunicationPackets {
|
||||
|
||||
public static byte[] convertToBytes(Object obj) {
|
||||
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
|
||||
|
||||
private static final byte INIT_PACKET = 0;
|
||||
private static final byte NOT_INIT_PACKET = 1;
|
||||
|
||||
|
||||
public static byte[] preparePacket(Object object) {
|
||||
return preparePacket(object, Communicator.get().getId());
|
||||
}
|
||||
|
||||
public static byte[] preparePacket(Object object, UUID id) {
|
||||
if (!isValidPacket(object)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final boolean isInitialPacket = isInitialPacket(object);
|
||||
final ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
|
||||
|
||||
try (ObjectOutputStream outputStream = new ObjectOutputStream(arrayOutputStream)) {
|
||||
outputStream.writeObject(obj);
|
||||
outputStream.writeObject(object);
|
||||
outputStream.flush();
|
||||
return arrayOutputStream.toByteArray();
|
||||
|
||||
final byte[] encryptedBytes = xor(arrayOutputStream.toByteArray(), isInitialPacket
|
||||
? Storage.TOKEN
|
||||
: id.toString()
|
||||
);
|
||||
|
||||
final byte[] bytes = new byte[encryptedBytes.length + 1];
|
||||
|
||||
bytes[0] = isInitialPacket ? INIT_PACKET : NOT_INIT_PACKET;
|
||||
System.arraycopy(encryptedBytes, 0, bytes, 1, bytes.length - 1);
|
||||
|
||||
return bytes;
|
||||
|
||||
} catch (Exception ignored) { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object buildFromBytes(byte[] bytes) {
|
||||
ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(bytes);
|
||||
public static Object readPacket(byte[] bytes) {
|
||||
return readPacket(bytes, Communicator.get().getId());
|
||||
}
|
||||
|
||||
public static Object readPacket(byte[] bytes, UUID id) {
|
||||
if (bytes.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final byte init = bytes[0];
|
||||
bytes = Arrays.copyOfRange(bytes, 1, bytes.length);
|
||||
|
||||
bytes = xor(bytes, isInitialPacket(init)
|
||||
? Storage.TOKEN
|
||||
: id.toString()
|
||||
);
|
||||
|
||||
final ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(bytes);
|
||||
|
||||
try (ObjectInput input = new ObjectInputStream(arrayInputStream)) {
|
||||
Object object = input.readObject();
|
||||
if (object.getClass() == null) return null;
|
||||
final Object object = input.readObject();
|
||||
|
||||
if (object.getClass() == null || !isValidPacket(object)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return object;
|
||||
} catch (Throwable ignored) { }
|
||||
} catch (Exception ignored) { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isPacket(Object object) {
|
||||
return object instanceof CommunicationPacket;
|
||||
// Yes, I am aware that xor is not the best encryption out there,
|
||||
// but it will suffice for now since the encryption shouldn't be too heavy.
|
||||
private static byte[] xor(byte[] bytes, String key) {
|
||||
final byte[] output = new byte[bytes.length];
|
||||
final byte[] secret = key.getBytes();
|
||||
|
||||
int pos = 0;
|
||||
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
output[i] = (byte) (bytes[i] ^ secret[pos]);
|
||||
pos += 1;
|
||||
|
||||
if (pos >= secret.length) {
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public interface CommunicationPacket {}
|
||||
public static boolean isValidPacket(Object object) {
|
||||
return object instanceof PATPacket;
|
||||
}
|
||||
|
||||
public static class BackendDataPacket implements CommunicationPacket, Serializable {
|
||||
private final String proxyToken, serverName, serverId;
|
||||
public static boolean isP2BPacket(Object object) {
|
||||
return object instanceof P2BPacket;
|
||||
}
|
||||
|
||||
public BackendDataPacket(String proxyToken, String serverId, String serverName) {
|
||||
this.proxyToken = proxyToken;
|
||||
this.serverId = serverId;
|
||||
this.serverName = serverName;
|
||||
}
|
||||
public static boolean isB2PPacket(Object object) {
|
||||
return object instanceof B2PPacket;
|
||||
}
|
||||
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
public static boolean isInitialPacket(Object object) {
|
||||
return object instanceof InitialPacket;
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
public static boolean isInitialPacket(byte[] bytes) {
|
||||
return bytes.length > 0 && isInitialPacket(bytes[0]);
|
||||
}
|
||||
|
||||
public boolean isToken(String token) {
|
||||
return proxyToken.equals(token);
|
||||
public static boolean isInitialPacket(byte b) {
|
||||
return b == INIT_PACKET;
|
||||
}
|
||||
|
||||
public interface PATPacket extends Serializable {
|
||||
String token = Storage.TOKEN;
|
||||
|
||||
default boolean tokenMatches(String token) {
|
||||
return PATPacket.token.equals(token);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UpdateCommandsPacket implements CommunicationPacket, Serializable {
|
||||
private final String proxyToken;
|
||||
private final UUID targetUUID;
|
||||
|
||||
public UpdateCommandsPacket(String proxyToken) {
|
||||
this.proxyToken = proxyToken;
|
||||
this.targetUUID = null;
|
||||
private interface InitialPacket extends PATPacket {}
|
||||
private interface Synchronizable extends Serializable {}
|
||||
|
||||
private interface P2BPacket extends PATPacket {}
|
||||
private interface B2PPacket extends PATPacket {}
|
||||
|
||||
|
||||
public static class Proxy2Backend {
|
||||
|
||||
private Proxy2Backend() { }
|
||||
|
||||
public record UpdatePacket(UUID playerId) implements P2BPacket {
|
||||
public boolean forEveryone() { return playerId == null; }
|
||||
}
|
||||
|
||||
public UpdateCommandsPacket(String proxyToken, UUID targetUUID) {
|
||||
this.proxyToken = proxyToken;
|
||||
this.targetUUID = targetUUID;
|
||||
}
|
||||
public record IdentityPacket(UUID targetServerId, String serverName) implements InitialPacket, P2BPacket { }
|
||||
|
||||
public boolean hasTargetUUID() {
|
||||
return targetUUID != null;
|
||||
}
|
||||
public record NotificationPacket(UUID playerId, String command) implements P2BPacket { }
|
||||
|
||||
public UUID getTargetUUID() {
|
||||
return targetUUID;
|
||||
}
|
||||
public record ExecuteConsoleCommandPacket(String command) implements P2BPacket { }
|
||||
|
||||
public boolean isToken(String token) {
|
||||
return proxyToken.equals(token);
|
||||
}
|
||||
}
|
||||
public record ExecutePlayerCommandPacket(UUID playerId, String command) implements P2BPacket { }
|
||||
|
||||
public static class FeedbackPacket implements CommunicationPacket, Serializable {
|
||||
private final String proxyToken, serverId;
|
||||
public record ConsoleMessagePacket(String message) implements P2BPacket { }
|
||||
|
||||
public FeedbackPacket(String proxyToken, String serverId) {
|
||||
this.proxyToken = proxyToken;
|
||||
this.serverId = serverId;
|
||||
}
|
||||
public record KeepAliveResponsePacket() implements P2BPacket { }
|
||||
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
public record DataSyncPacket(
|
||||
Messages messages,
|
||||
AutoLowerCase autoLowerCase,
|
||||
UnknownCommand unknownCommand
|
||||
) implements P2BPacket {
|
||||
|
||||
public boolean isToken(String token) {
|
||||
return proxyToken.equals(token);
|
||||
}
|
||||
}
|
||||
public record Messages(String prefix)
|
||||
implements Synchronizable {}
|
||||
|
||||
public static class RequestPacket implements CommunicationPacket, Serializable {
|
||||
private final String proxyToken, serverId;
|
||||
public record AutoLowerCase(boolean enabled)
|
||||
implements Synchronizable {}
|
||||
|
||||
public RequestPacket(String proxyToken, String serverId) {
|
||||
this.proxyToken = proxyToken;
|
||||
this.serverId = serverId;
|
||||
}
|
||||
public record UnknownCommand(boolean enabled, MultipleMessagesHelper message)
|
||||
implements Synchronizable {}
|
||||
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
public boolean isToken(String token) {
|
||||
return proxyToken.equals(token);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ForcePermissionResetPacket implements Serializable {
|
||||
|
||||
private final String proxyToken;
|
||||
private UUID targetUUID = null;
|
||||
|
||||
public ForcePermissionResetPacket(String proxyToken) {
|
||||
this.proxyToken = proxyToken;
|
||||
}
|
||||
|
||||
public ForcePermissionResetPacket(String proxyToken, UUID targetUUID) {
|
||||
this.proxyToken = proxyToken;
|
||||
this.targetUUID = targetUUID;
|
||||
}
|
||||
|
||||
public UUID getTargetUUID() {
|
||||
return targetUUID;
|
||||
}
|
||||
|
||||
public boolean hasTarget() {
|
||||
return targetUUID != null;
|
||||
}
|
||||
|
||||
public boolean isToken(String token) {
|
||||
return proxyToken.equals(token);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketBundle implements CommunicationPacket, Serializable {
|
||||
|
||||
private final CommandsPacket commandsPacket;
|
||||
private final GroupsPacket groupsPacket;
|
||||
private final UnknownCommandPacket unknownCommandPacket;
|
||||
private final NamespaceCommandsPacket namespaceCommandsPacket;
|
||||
private final MessagePacket messagePacket;
|
||||
private final String proxyToken, serverId;
|
||||
private final boolean velocity;
|
||||
|
||||
public PacketBundle(String proxyToken, String serverId, CommandsPacket commandsPacket, GroupsPacket groupsPacket) {
|
||||
this.proxyToken = proxyToken;
|
||||
this.serverId = serverId;
|
||||
this.commandsPacket = commandsPacket;
|
||||
this.groupsPacket = groupsPacket;
|
||||
this.unknownCommandPacket = new UnknownCommandPacket();
|
||||
this.namespaceCommandsPacket = new NamespaceCommandsPacket();
|
||||
this.messagePacket = new MessagePacket();
|
||||
this.velocity = Reflection.isVelocityServer();
|
||||
}
|
||||
|
||||
public boolean isVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public boolean isToken(String token) {
|
||||
return proxyToken.equals(token);
|
||||
}
|
||||
|
||||
public boolean isId(String id) {
|
||||
return idIgnored() || serverId.equals(id);
|
||||
}
|
||||
|
||||
public boolean idIgnored() {
|
||||
return serverId == null;
|
||||
}
|
||||
|
||||
public CommandsPacket getCommandsPacket() {
|
||||
return commandsPacket;
|
||||
}
|
||||
|
||||
public GroupsPacket getGroupsPacket() {
|
||||
return groupsPacket;
|
||||
}
|
||||
|
||||
public UnknownCommandPacket getUnknownCommandPacket() { return unknownCommandPacket; }
|
||||
|
||||
public MessagePacket getMessagePacket() {
|
||||
return messagePacket;
|
||||
}
|
||||
|
||||
public NamespaceCommandsPacket getNamespaceCommandsPacket() {
|
||||
return namespaceCommandsPacket;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MessagePacket implements Serializable {
|
||||
|
||||
private final String prefix;
|
||||
private final MultipleMessagesHelper baseBlockedMessage, subBlockedMessage;
|
||||
|
||||
public MessagePacket() {
|
||||
prefix = Storage.ConfigSections.Messages.PREFIX.PREFIX;
|
||||
baseBlockedMessage = Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE;
|
||||
subBlockedMessage = Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public MultipleMessagesHelper getBaseBlockedMessage() {
|
||||
return baseBlockedMessage;
|
||||
}
|
||||
|
||||
public MultipleMessagesHelper getSubBlockedMessage() {
|
||||
return subBlockedMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class NamespaceCommandsPacket implements Serializable {
|
||||
public static class Backend2Proxy {
|
||||
|
||||
private final boolean enabled;
|
||||
private Backend2Proxy() { }
|
||||
|
||||
public NamespaceCommandsPacket() {
|
||||
enabled = Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.ENABLED;
|
||||
}
|
||||
public record IdentityRequestPacket(UUID serverId) implements InitialPacket, B2PPacket { }
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
public record IdentityResponsePacket(UUID serverId) implements InitialPacket, B2PPacket { }
|
||||
|
||||
public static class UnknownCommandPacket implements Serializable {
|
||||
public record DataSyncReceivedPacket() implements B2PPacket { }
|
||||
|
||||
private final MultipleMessagesHelper message;
|
||||
private final boolean enabled;
|
||||
public record KeepAlivePacket() implements B2PPacket { }
|
||||
|
||||
public UnknownCommandPacket() {
|
||||
enabled = Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED;
|
||||
message = Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE;
|
||||
}
|
||||
|
||||
public MultipleMessagesHelper getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandsPacket implements Serializable {
|
||||
|
||||
private List<String> commands;
|
||||
private boolean turnBlacklistToWhitelist;
|
||||
|
||||
public void setCommands(List<String> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public void setTurnBlacklistToWhitelist(boolean turnBlacklistToWhitelist) {
|
||||
this.turnBlacklistToWhitelist = turnBlacklistToWhitelist;
|
||||
}
|
||||
|
||||
public boolean turnBlacklistToWhitelistEnabled() {
|
||||
return turnBlacklistToWhitelist;
|
||||
}
|
||||
|
||||
public List<String> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
|
||||
public static class GroupsPacket implements Serializable {
|
||||
|
||||
private final List<TinyGroup> groups;
|
||||
|
||||
public GroupsPacket(List<TinyGroup> groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
public List<TinyGroup> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,58 +5,10 @@ import io.netty.buffer.*;
|
||||
|
||||
public class PacketUtils {
|
||||
|
||||
/*
|
||||
Copyright (c) 2012, md_5. All rights reserved.
|
||||
Original code from Bungeecord source:
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L72-L94
|
||||
*/
|
||||
|
||||
public static String readString(ByteBuf buf) throws Exception {
|
||||
return readString( buf, Short.MAX_VALUE );
|
||||
}
|
||||
|
||||
public static String readString(ByteBuf byteBuf, int maxLength) throws Exception {
|
||||
int len = readVarInt(byteBuf);
|
||||
if ( len > maxLength * 3 )
|
||||
throw new Exception("Cannot receive string longer than " + maxLength * 3 + " (got " + len + " bytes)" );
|
||||
|
||||
String string = byteBuf.toString(byteBuf.readerIndex(), len, StandardCharsets.UTF_8);
|
||||
byteBuf.readerIndex(byteBuf.readerIndex() + len );
|
||||
|
||||
if (string.length() > maxLength)
|
||||
throw new Exception( "Cannot receive string longer than " + maxLength + " (got " + string.length() + " characters)" );
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
/*
|
||||
Copyright (c) 2012, md_5. All rights reserved.
|
||||
Original code from Bungeecord source:
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L233-L261
|
||||
*/
|
||||
|
||||
public static int readVarInt(ByteBuf input) throws Exception {
|
||||
return readVarInt(input, 5);
|
||||
}
|
||||
|
||||
public static int readVarInt(ByteBuf input, int maxBytes) throws Exception {
|
||||
int out = 0, bytes = 0;
|
||||
byte in;
|
||||
|
||||
while (true) {
|
||||
in = input.readByte();
|
||||
out |= (in & 0x7F) << (bytes++ * 7);
|
||||
if (bytes > maxBytes) throw new Exception( "VarInt too big (max " + maxBytes + ")" );
|
||||
if ((in & 0x80) != 0x80) break;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
Copyright (c) 2012, md_5. All rights reserved.
|
||||
Original code from Bungeecord source:
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L263C1-L283C6
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L307-L327
|
||||
*/
|
||||
|
||||
public static void writeVarInt(int value, ByteBuf output) {
|
||||
@@ -75,7 +27,7 @@ public class PacketUtils {
|
||||
/*
|
||||
Copyright (c) 2012, md_5. All rights reserved.
|
||||
Original code from Bungeecord source:
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L50C4-L71C1
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L88-L108
|
||||
*/
|
||||
|
||||
public static void writeString(String string, ByteBuf byteBuf) throws Exception {
|
||||
|
||||
@@ -9,53 +9,40 @@ import java.util.*;
|
||||
|
||||
public class Reflection {
|
||||
|
||||
private static boolean legacy, proxy, velocity, paper, folia, weird, oldChannelMethod;
|
||||
private static String versionName, fullVersionName, rawVersionName, versionPackageName;
|
||||
private static Version version;
|
||||
private static boolean legacy, weird, oldChannelMethod;
|
||||
private static String versionName, rawVersionName, versionPackageName;
|
||||
private static int major, minor, release;
|
||||
|
||||
private static Software software;
|
||||
|
||||
public static void initialize(Object serverObj) {
|
||||
try {
|
||||
Class.forName("org.bukkit.Server");
|
||||
loadVersionName(serverObj);
|
||||
loadAges();
|
||||
loadVersionEnum();
|
||||
legacy = minor <= 16;
|
||||
weird = Reflection.getMinor() == 20 && Reflection.getRelease() >= 6 || Reflection.getMinor() > 20;
|
||||
proxy = false;
|
||||
} catch (Throwable ignored) { proxy = true; }
|
||||
|
||||
if (!proxy) {
|
||||
if (doesClassExist("org.bukkit.Server")) {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
folia = true;
|
||||
} catch (Throwable throwable) {
|
||||
folia = false;
|
||||
|
||||
software = doesClassExist("io.papermc.paper.threadedregions.RegionizedServer")
|
||||
? Software.FOLIA : doesClassExist("com.destroystokyo.paper.Metrics")
|
||||
? Software.PAPER : doesClassExist("org.spigotmc.SpigotConfig")
|
||||
? Software.SPIGOT : Software.BUKKIT;
|
||||
|
||||
|
||||
loadVersionName(serverObj);
|
||||
loadAges();
|
||||
|
||||
legacy = isAtMost(1, 16);
|
||||
weird = isAtLeast(1, 20, 6);
|
||||
|
||||
oldChannelMethod = software.isPaperBased() && weird;
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("com.destroystokyo.paper.Metrics");
|
||||
paper = true;
|
||||
} catch (Throwable throwable) {
|
||||
try {
|
||||
Class.forName("io.github.waterfallmc.waterfall.QueryResult");
|
||||
paper = true;
|
||||
} catch (Throwable throwable1) {
|
||||
paper = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (proxy) {
|
||||
try {
|
||||
Class.forName("com.velocitypowered.api.proxy.ProxyServer");
|
||||
velocity = true;
|
||||
} catch (ClassNotFoundException ignored) { velocity = false; }
|
||||
}
|
||||
|
||||
if (proxy) version = Version.UNKNOWN;
|
||||
|
||||
oldChannelMethod = folia || paper && Reflection.isWeird();
|
||||
software = doesClassExist("com.velocitypowered.api.proxy.ProxyServer")
|
||||
? Software.VELOCITY : doesClassExist("io.github.waterfallmc.waterfall.QueryResult")
|
||||
? Software.WATERFALL : Software.BUNGEECORD;
|
||||
}
|
||||
|
||||
public static void toggleInjectionMethod() {
|
||||
@@ -67,22 +54,31 @@ public class Reflection {
|
||||
public static int[] getAges() { return new int[]{major, minor, release}; }
|
||||
public static String getVersionName() { return versionName; }
|
||||
public static String getRawVersionName() { return rawVersionName; }
|
||||
public static Version getVersion() { return version; }
|
||||
public static boolean isModern() { return !legacy; }
|
||||
public static boolean isLegacy() { return legacy; }
|
||||
public static boolean isWeird() { return weird; }
|
||||
|
||||
public static Software getSoftware() {
|
||||
return software;
|
||||
}
|
||||
|
||||
public static boolean isFoliaServer() {
|
||||
return folia;
|
||||
return software == Software.FOLIA;
|
||||
}
|
||||
|
||||
public static boolean isCraftbukkit() {
|
||||
return software == Software.BUKKIT;
|
||||
}
|
||||
|
||||
public static boolean isProxyServer() {
|
||||
return proxy;
|
||||
return software.isProxySoftware();
|
||||
}
|
||||
public static boolean isVelocityServer() {
|
||||
return velocity;
|
||||
return software == Software.VELOCITY;
|
||||
}
|
||||
public static boolean isPaper() {
|
||||
return software == Software.PAPER;
|
||||
}
|
||||
public static boolean isPaper() { return paper; }
|
||||
|
||||
public static Class<?> getClass(String clazzPath) {
|
||||
Class<?> clazz = null;
|
||||
@@ -301,7 +297,7 @@ public class Reflection {
|
||||
}
|
||||
|
||||
public static Object getPlayerNetworkManager(Object playerConnection) throws Exception {
|
||||
Optional<Field> optional = getFieldsByType(Reflection.getMinor() == 20 && Reflection.getRelease() > 2 || Reflection.getMinor() > 20 ? playerConnection.getClass().getSuperclass() : playerConnection.getClass(), "NetworkManager", SearchOption.ENDS).stream().findFirst();
|
||||
Optional<Field> optional = getFieldsByType(Reflection.isAfter(1, 20, 2) ? playerConnection.getClass().getSuperclass() : playerConnection.getClass(), "NetworkManager", SearchOption.ENDS).stream().findFirst();
|
||||
if(!optional.isPresent()) return null;
|
||||
return optional.get().get(playerConnection);
|
||||
}
|
||||
@@ -352,57 +348,106 @@ public class Reflection {
|
||||
|
||||
|
||||
private static void loadVersionName(Object serverObject) throws Exception {
|
||||
versionName = proxy ? ProxyServer.getInstance().getName() : Bukkit.getName();
|
||||
versionName = software.proxySoftware ? ProxyServer.getInstance().getName() : Bukkit.getName();
|
||||
rawVersionName = (String) serverObject.getClass().getMethod("getBukkitVersion").invoke(serverObject);
|
||||
fullVersionName = rawVersionName;
|
||||
rawVersionName = rawVersionName.split("-")[0].replace(".", "_");
|
||||
versionPackageName = serverObject.getClass().getPackage().getName();
|
||||
versionPackageName = versionPackageName.substring(versionPackageName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
private static void loadVersionEnum() {
|
||||
try {
|
||||
final String primaryVersionName, fullVersionName;
|
||||
StringBuilder builder = new StringBuilder("v_");
|
||||
builder.append(major).append("_").append(minor);
|
||||
primaryVersionName = builder.toString();
|
||||
if (release != 0) builder.append("_").append(release);
|
||||
fullVersionName = builder.toString();
|
||||
boolean couldFindOriginalVersion = Arrays.stream(Version.values()).anyMatch(searchingVersion -> searchingVersion.toString().equals(fullVersionName));
|
||||
version = Version.valueOf(couldFindOriginalVersion ? fullVersionName : primaryVersionName);
|
||||
} catch (Exception exception) {
|
||||
version = Version.UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadAges() {
|
||||
String[] versionArgs = rawVersionName.split("_");
|
||||
final String[] versionArgs = rawVersionName.split("_");
|
||||
|
||||
major = Integer.parseInt(versionArgs[0]);
|
||||
minor = Integer.parseInt(versionArgs[1]);
|
||||
release = versionArgs.length > 2 ? Integer.parseInt(versionArgs[2]) : 0;
|
||||
|
||||
if (versionArgs.length >= 3) {
|
||||
|
||||
try {
|
||||
release = Integer.parseInt(versionArgs[2]);
|
||||
return;
|
||||
} catch (NumberFormatException ignored) {}
|
||||
|
||||
}
|
||||
|
||||
release = 0;
|
||||
}
|
||||
|
||||
public static int getMajor() { return major; }
|
||||
public static int getMinor() { return minor; }
|
||||
public static int getRelease() { return release; }
|
||||
|
||||
public enum Version {
|
||||
UNKNOWN, UNSUPPORTED,
|
||||
v_1_8, v_1_8_8,
|
||||
v_1_9, v_1_9_4,
|
||||
v_1_10, v_1_10_2,
|
||||
v_1_11, v_1_11_2,
|
||||
v_1_12, v_1_12_2,
|
||||
v_1_13, v_1_13_2,
|
||||
v_1_14, v_1_14_4,
|
||||
v_1_15, v_1_15_2,
|
||||
v_1_16, v_1_16_4, v_1_16_5,
|
||||
v_1_17, v_1_17_1, v_1_18,
|
||||
v_1_18_1, v_1_18_2,
|
||||
v_1_19, v_1_19_1, v_1_19_2, v_1_19_3, v_1_19_4,
|
||||
v_1_20, v_1_20_1, v_1_20_2, v_1_20_3, v_1_20_4, v_1_20_5, v_1_20_6,
|
||||
v_1_21, v_1_21_1, v_1_21_2, v_1_21_3, v_1_21_4, v_1_21_5, v_1_21_6, v_1_21_7, v_1_21_8,
|
||||
v_1_22, v_1_22_1, v_1_22_2
|
||||
public static boolean isAtLeast(int major, int minor) {
|
||||
return Reflection.getMajor() > major || (Reflection.getMajor() == major && Reflection.getMinor() >= minor);
|
||||
}
|
||||
|
||||
public static boolean isAtLeast(int major, int minor, int release) {
|
||||
return Reflection.getMajor() > major
|
||||
|| (Reflection.getMajor() == major && Reflection.getMinor() > minor)
|
||||
|| (Reflection.getMajor() == major && Reflection.getMinor() == minor && Reflection.getRelease() >= release);
|
||||
}
|
||||
|
||||
public static boolean isAtMost(int major, int minor) {
|
||||
return Reflection.getMajor() < major || (Reflection.getMajor() == major && Reflection.getMinor() <= minor);
|
||||
}
|
||||
|
||||
public static boolean isAtMost(int major, int minor, int release) {
|
||||
return Reflection.getMajor() < major
|
||||
|| (Reflection.getMajor() == major && Reflection.getMinor() < minor)
|
||||
|| (Reflection.getMajor() == major && Reflection.getMinor() == minor && Reflection.getRelease() <= release);
|
||||
}
|
||||
|
||||
public static boolean isAfter(int major, int minor) {
|
||||
return Reflection.getMajor() > major || (Reflection.getMajor() == major && Reflection.getMinor() > minor);
|
||||
}
|
||||
|
||||
public static boolean isAfter(int major, int minor, int release) {
|
||||
return Reflection.getMajor() > major
|
||||
|| (Reflection.getMajor() == major && Reflection.getMinor() > minor)
|
||||
|| (Reflection.getMajor() == major && Reflection.getMinor() == minor && Reflection.getRelease() > release);
|
||||
}
|
||||
|
||||
public static boolean isBefore(int major, int minor) {
|
||||
return Reflection.getMajor() < major || (Reflection.getMajor() == major && Reflection.getMinor() < minor);
|
||||
}
|
||||
|
||||
public static boolean isBefore(int major, int minor, int release) {
|
||||
return Reflection.getMajor() < major
|
||||
|| (Reflection.getMajor() == major && Reflection.getMinor() < minor)
|
||||
|| (Reflection.getMajor() == major && Reflection.getMinor() == minor && Reflection.getRelease() < release);
|
||||
}
|
||||
|
||||
public enum Software {
|
||||
BUKKIT(false, false),
|
||||
SPIGOT(false, false),
|
||||
PAPER(true, false),
|
||||
FOLIA(true, false),
|
||||
|
||||
BUNGEECORD(false, true),
|
||||
WATERFALL(true, true),
|
||||
VELOCITY(true, true);
|
||||
|
||||
private final String name;
|
||||
private final boolean paperBased, proxySoftware;
|
||||
|
||||
Software(final boolean paperBased, final boolean proxySoftware) {
|
||||
this.paperBased = paperBased;
|
||||
this.proxySoftware = proxySoftware;
|
||||
this.name = Character.toUpperCase(this.name().charAt(0)) + this.name().substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isPaperBased() {
|
||||
return paperBased;
|
||||
}
|
||||
|
||||
public boolean isProxySoftware() {
|
||||
return proxySoftware;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SearchOption { CONTAINS, EQUALS, ENDS, STARTS }
|
||||
|
||||
@@ -34,12 +34,32 @@ public class TimeConverter {
|
||||
}
|
||||
|
||||
StringBuilder uptimeText = new StringBuilder();
|
||||
if (weeks > 0) uptimeText.append(weeks + "w, ");
|
||||
else if (days > 0) uptimeText.append(days + "d, ");
|
||||
else if (hours > 0) uptimeText.append(hours + "h, ");
|
||||
else if (minutes > 0) uptimeText.append(minutes + "m, ");
|
||||
else if (seconds > 0) uptimeText.append(seconds + "s");
|
||||
else uptimeText.append(ms + "ms");
|
||||
|
||||
if (weeks > 0) {
|
||||
uptimeText.append(weeks).append("w");
|
||||
}
|
||||
|
||||
if (days > 0) {
|
||||
if (weeks > 0) uptimeText.append(", ");
|
||||
uptimeText.append(days).append("d");
|
||||
}
|
||||
|
||||
if (hours > 0) {
|
||||
if (days > 0) uptimeText.append(", ");
|
||||
uptimeText.append(hours).append("h");
|
||||
}
|
||||
|
||||
if (minutes > 0) {
|
||||
if (hours > 0) uptimeText.append(", ");
|
||||
uptimeText.append(minutes).append("m");
|
||||
}
|
||||
|
||||
if (seconds > 0) {
|
||||
if (minutes > 0) uptimeText.append(", ");
|
||||
uptimeText.append(seconds).append("s");
|
||||
} else {
|
||||
uptimeText.append(ms).append("ms");
|
||||
}
|
||||
|
||||
return uptimeText.toString();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class VersionComparer {
|
||||
if (shouldAnnounce) {
|
||||
shouldAnnounce = false;
|
||||
|
||||
Logger.info("§8[§fPAT | Bukkit§8] §7Please be aware that you are currently using a §bdeveloper §7version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.");
|
||||
Logger.info("§8[§fPAT | " + (Reflection.isProxyServer() ? "Proxy" : "Bukkit") + "§8] §7Please be aware that you are currently using a §bdeveloper §7version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class GroupManagerAdapter implements Listener {
|
||||
.filter(permission -> permission.startsWith("proantitab."))
|
||||
.forEach(permission -> PermissionUtil.setPermission(uuid, permission, true));
|
||||
|
||||
if (Reflection.getMinor() >= 13) {
|
||||
if (Reflection.isAtLeast(1, 13)) {
|
||||
BukkitAntiTabListener.handleTabCompletion(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.BukkitAntiTabListener;
|
||||
import de.rayzs.pat.utils.permission.PermissionPlugin;
|
||||
import de.rayzs.pat.utils.scheduler.PATScheduler;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.event.sync.PreNetworkSyncEvent;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
@@ -15,6 +16,8 @@ import net.luckperms.api.event.node.*;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import net.luckperms.api.node.*;
|
||||
import net.luckperms.api.*;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class LuckPermsAdapter {
|
||||
@@ -44,17 +47,29 @@ public class LuckPermsAdapter {
|
||||
}
|
||||
|
||||
public static Map<String, Boolean> getPermissions(UUID uuid) {
|
||||
User user = getUser(uuid);
|
||||
if (user == null) return null;
|
||||
final User user = PROVIDER.getUserManager().getUser(uuid);
|
||||
|
||||
return user.getCachedData().getPermissionData().getPermissionMap();
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
|
||||
if (Storage.ConfigSections.Settings.UPDATE_GROUPS_PER_SERVER.ENABLED || Storage.ConfigSections.Settings.UPDATE_GROUPS_PER_WORLD.ENABLED) {
|
||||
final String contextValue = Storage.getLoader().getPlayerServerName(uuid);
|
||||
|
||||
if (contextValue != null) {
|
||||
builder.add("server", contextValue).add("world", contextValue);
|
||||
}
|
||||
}
|
||||
|
||||
return user.getCachedData().getPermissionData(QueryOptions.contextual(builder.build())).getPermissionMap();
|
||||
}
|
||||
|
||||
public static void setPermissions(UUID uuid) {
|
||||
Map<String, Boolean> permissions = getPermissions(uuid);
|
||||
if (permissions == null) return;
|
||||
|
||||
|
||||
permissions.forEach((permission, permitted) -> {
|
||||
|
||||
if (permission.startsWith("proantitab.") || permission.equals("*"))
|
||||
@@ -67,7 +82,7 @@ public class LuckPermsAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Reflection.getMinor() >= 13)
|
||||
if (Reflection.isAtLeast(1, 13))
|
||||
BukkitAntiTabListener.handleTabCompletion(uuid);
|
||||
}
|
||||
|
||||
@@ -92,10 +107,11 @@ public class LuckPermsAdapter {
|
||||
if (event.isUser() && event.getTarget() instanceof User) {
|
||||
User user = (User) event.getTarget();
|
||||
UUID uuid = user.getUniqueId();
|
||||
String serverName = Storage.getLoader().getPlayerServerName(uuid);
|
||||
|
||||
if (Reflection.isProxyServer()) {
|
||||
PermissionUtil.reloadPermissions(user.getUniqueId());
|
||||
Communicator.sendUpdateCommand(uuid);
|
||||
Communicator.Proxy2Backend.sendUpdateCommand(uuid, serverName);
|
||||
|
||||
if (Reflection.isVelocityServer()) {
|
||||
VelocityLoader.delayedPlayerReload(uuid);
|
||||
|
||||
@@ -11,6 +11,7 @@ import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.configuration.ConfigurationBuilder;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
public class Group implements Serializable {
|
||||
|
||||
@@ -108,6 +109,10 @@ public class Group implements Serializable {
|
||||
|
||||
public void add(String command) {
|
||||
this.generalGroupBlacklist.add(command).save();
|
||||
|
||||
if (command.startsWith("plugin=") || command.startsWith("!")) {
|
||||
this.generalGroupBlacklist.load();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(String command, String server) {
|
||||
@@ -118,6 +123,10 @@ public class Group implements Serializable {
|
||||
|
||||
public void remove(String command) {
|
||||
this.generalGroupBlacklist.remove(command).save();
|
||||
|
||||
if (command.startsWith("plugin=") || command.startsWith("!")) {
|
||||
this.generalGroupBlacklist.load();
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(String command, String server) {
|
||||
@@ -128,6 +137,7 @@ public class Group implements Serializable {
|
||||
|
||||
public void clear() {
|
||||
this.generalGroupBlacklist.clear().save();
|
||||
this.generalGroupBlacklist.load();
|
||||
}
|
||||
|
||||
public void clear(String server) {
|
||||
@@ -146,8 +156,12 @@ public class Group implements Serializable {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public boolean hasPermission(Object targetObj) {
|
||||
return PermissionUtil.hasPermission(targetObj, "group." + this.groupName);
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return PermissionUtil.hasPermission(sender, "group." + this.groupName);
|
||||
}
|
||||
|
||||
public boolean hasPermission(UUID uuid) {
|
||||
return PermissionUtil.hasPermission(uuid, "group." + this.groupName);
|
||||
}
|
||||
|
||||
public boolean contains(String command) {
|
||||
|
||||
@@ -9,76 +9,89 @@ import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
|
||||
public class GroupManager {
|
||||
|
||||
private static final List<Group> GROUPS = new LinkedList<>();
|
||||
private static final int INVALID_GROUP_PRIORITY = Integer.MAX_VALUE -1;
|
||||
|
||||
public static void initialize() {
|
||||
|
||||
Object obj = Storage.Files.STORAGE.get("groups");
|
||||
|
||||
if (obj == null) {
|
||||
Logger.info("No groups found. Skipping...");
|
||||
return;
|
||||
}
|
||||
|
||||
Storage.Files.STORAGE.getKeys("groups", false).forEach(GroupManager::registerGroup);
|
||||
if(!Reflection.isProxyServer()) return;
|
||||
|
||||
if (!Reflection.isProxyServer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getGroups().forEach(group -> {
|
||||
|
||||
Object objServ = Storage.Files.STORAGE.get("groups." + group.getGroupName() + ".servers");
|
||||
|
||||
if (objServ == null) {
|
||||
//Logger.info("Group " + group.getGroupName() + " has no servers. Skipping...");
|
||||
return;
|
||||
}
|
||||
|
||||
Storage.Files.STORAGE.getKeys("groups." + group.getGroupName() + ".servers", false).forEach(key -> {
|
||||
group.getOrCreateGroupBlacklist(key, true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Group> getPlayerGroups(Object player) {
|
||||
final int invalidPriority = Integer.MAX_VALUE -1;
|
||||
|
||||
List<Group> playerGroups = new ArrayList<>(GroupManager.getGroups().stream().filter(group -> group.hasPermission(player)).toList());
|
||||
|
||||
int priority = playerGroups.stream()
|
||||
.mapToInt(Group::getPriority)
|
||||
.filter(group -> group <= invalidPriority)
|
||||
.min().orElse(invalidPriority);
|
||||
|
||||
playerGroups.removeIf(group -> group.getPriority() > priority);
|
||||
|
||||
return playerGroups;
|
||||
}
|
||||
|
||||
public static List<Group> getPlayerGroups(UUID uuid) {
|
||||
final int invalidPriority = Integer.MAX_VALUE -1;
|
||||
|
||||
List<Group> playerGroups = new ArrayList<>(GroupManager.getGroups().stream().filter(group -> group.hasPermission(uuid)).toList());
|
||||
|
||||
int priority = playerGroups.stream()
|
||||
.mapToInt(Group::getPriority)
|
||||
.filter(group -> group <= invalidPriority)
|
||||
.min().orElse(invalidPriority);
|
||||
.filter(group -> group <= INVALID_GROUP_PRIORITY)
|
||||
.min().orElse(INVALID_GROUP_PRIORITY);
|
||||
|
||||
playerGroups.removeIf(group -> group.getPriority() > priority);
|
||||
|
||||
return playerGroups;
|
||||
}
|
||||
|
||||
public static boolean canAccessCommand(Object targetObj, String unmodifiedCommand, Storage.Blacklist.BlockType type) {
|
||||
return canAccessCommand(targetObj, unmodifiedCommand, type, null);
|
||||
public static List<Group> getPlayerGroups(CommandSender sender) {
|
||||
List<Group> playerGroups = new ArrayList<>(GroupManager.getGroups().stream().filter(group -> group.hasPermission(sender)).toList());
|
||||
|
||||
int priority = playerGroups.stream()
|
||||
.mapToInt(Group::getPriority)
|
||||
.filter(group -> group <= INVALID_GROUP_PRIORITY)
|
||||
.min().orElse(INVALID_GROUP_PRIORITY);
|
||||
|
||||
playerGroups.removeIf(group -> group.getPriority() > priority);
|
||||
return playerGroups;
|
||||
}
|
||||
|
||||
public static boolean canAccessCommand(Object targetObj, String unmodifiedCommand, Storage.Blacklist.BlockType type, String server) {
|
||||
final CommandSender sender = CommandSenderHandler.from(targetObj);
|
||||
public static AccessResult canAccessCommand(List<Group> groups, String unmodifiedCommand, Storage.Blacklist.BlockType type) {
|
||||
return canAccessCommand(groups, unmodifiedCommand, type, null);
|
||||
}
|
||||
|
||||
if (sender == null) {
|
||||
Logger.warning("Failed to load player! (GroupManager#62)");
|
||||
return false;
|
||||
public static AccessResult canAccessCommand(List<Group> groups, String unmodifiedCommand, Storage.Blacklist.BlockType type, String server) {
|
||||
if (groups == null || groups.isEmpty()) {
|
||||
return AccessResult.NO_GROUPS;
|
||||
}
|
||||
|
||||
final List<Group> playerGroups = sender.getGroups();
|
||||
|
||||
if (playerGroups == null || playerGroups.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String command = type.toString() + unmodifiedCommand;
|
||||
String allCommand = type + "*";
|
||||
String negatedCommand = type.toString() + BlockType.NEGATE + unmodifiedCommand;
|
||||
|
||||
boolean permitted = false;
|
||||
for (Group group : playerGroups) {
|
||||
boolean all = false,
|
||||
permitted = false,
|
||||
negated = false;
|
||||
|
||||
for (Group group : groups) {
|
||||
|
||||
all = group.contains(allCommand);
|
||||
permitted = group.contains(command);
|
||||
negated = group.contains(negatedCommand);
|
||||
|
||||
if (permitted) {
|
||||
break;
|
||||
@@ -90,21 +103,38 @@ public class GroupManager {
|
||||
|
||||
for (String s : servers) {
|
||||
|
||||
if (group.contains(command, s)) {
|
||||
permitted = true;
|
||||
break;
|
||||
if (!all) {
|
||||
all = group.contains(allCommand, s);
|
||||
}
|
||||
|
||||
if (!permitted) {
|
||||
permitted = group.contains(command, s);
|
||||
}
|
||||
|
||||
if (!negated) {
|
||||
negated = group.contains(negatedCommand, s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (permitted) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (negated) {
|
||||
return AccessResult.NEGATED;
|
||||
}
|
||||
|
||||
if (all) {
|
||||
return AccessResult.ALLOWED;
|
||||
}
|
||||
|
||||
if (!permitted && type != BlockType.BOTH)
|
||||
return canAccessCommand(targetObj, unmodifiedCommand, Storage.Blacklist.BlockType.BOTH, server);
|
||||
|
||||
return permitted;
|
||||
return canAccessCommand(groups, unmodifiedCommand, Storage.Blacklist.BlockType.BOTH, server);
|
||||
|
||||
return permitted ? AccessResult.ALLOWED : AccessResult.NOT_LISTED;
|
||||
}
|
||||
|
||||
public static void setGroup(String groupName, List<String> commands) {
|
||||
@@ -251,4 +281,19 @@ public class GroupManager {
|
||||
public static boolean isGroupRegistered(String groupName) {
|
||||
return getGroupByName(groupName) != null;
|
||||
}
|
||||
|
||||
public enum AccessResult {
|
||||
ALLOWED(true), NEGATED(false),
|
||||
NO_GROUPS(false), NOT_LISTED(false),
|
||||
UNKNOWN(false);
|
||||
|
||||
private final boolean bool;
|
||||
AccessResult(boolean bool) {
|
||||
this.bool = bool;
|
||||
}
|
||||
|
||||
public boolean asBoolean() {
|
||||
return this.bool;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,12 +41,13 @@ public class MessageTranslator {
|
||||
for (Map.Entry<Character, String> entry : colors.entrySet())
|
||||
endingColors.put(entry.getKey(), "</" + entry.getValue().substring(1));
|
||||
|
||||
support = !Storage.USE_SIMPLECLOUD && (Reflection.getMinor() >= 18 || Reflection.isProxyServer());
|
||||
support = !Reflection.isCraftbukkit() && (Reflection.isAtLeast(1, 18) || Reflection.isProxyServer());
|
||||
|
||||
if(support)
|
||||
if (support) {
|
||||
translator = Reflection.isVelocityServer() ? new VelocityMessageTranslator()
|
||||
: Reflection.isProxyServer() ? new BungeeMessageTranslator()
|
||||
: new BukkitMessageTranslator();
|
||||
}
|
||||
}
|
||||
|
||||
public static String translateLegacy(String text) {
|
||||
@@ -128,7 +129,7 @@ public class MessageTranslator {
|
||||
: sender.getName();
|
||||
|
||||
String token = (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED || Reflection.isProxyServer())
|
||||
? Storage.TOKEN
|
||||
? Storage.CENSORED_TOKEN
|
||||
: "/";
|
||||
|
||||
String serverName = Storage.SERVER_NAME == null ? "/" : Storage.SERVER_NAME;
|
||||
@@ -141,6 +142,7 @@ public class MessageTranslator {
|
||||
"%pat_general_prefix%", Storage.ConfigSections.Messages.PREFIX.PREFIX,
|
||||
"%token%", token,
|
||||
"%sync_server_name%", serverName,
|
||||
"%server%", serverName,
|
||||
"%current_version%", Storage.CURRENT_VERSION,
|
||||
"%newest_version%", Storage.NEWER_VERSION
|
||||
);
|
||||
@@ -148,10 +150,6 @@ public class MessageTranslator {
|
||||
return PlaceholderReplacer.replace(targetObj, text);
|
||||
}
|
||||
|
||||
public static String replaceMessageString(String rawText, String... replacements) {
|
||||
return replaceMessage(StringUtils.replace(rawText, replacements));
|
||||
}
|
||||
|
||||
public static String replaceMessageString(Object targetObj, String rawText, String... replacements) {
|
||||
return replaceMessage(targetObj, StringUtils.replace(rawText, replacements));
|
||||
}
|
||||
@@ -189,8 +187,16 @@ public class MessageTranslator {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String translateIntoMiniMessage(String text) {
|
||||
return translator.translate(replaceMessage(text));
|
||||
public static void sendActionbar(Object targetObj, String message) {
|
||||
translator.sendActionbar(targetObj, message);
|
||||
}
|
||||
|
||||
public static void sendTitle(Object targetObj, String title, String subtitle, int fadeIn, int stay, int fadeOut) {
|
||||
translator.sendTitle(targetObj, title, subtitle, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
public static void playSound(Object targetObj, String soundKey, float volume, float pitch) throws Exception {
|
||||
translator.playSound(targetObj, soundKey, volume, pitch);
|
||||
}
|
||||
|
||||
public static void closeAudiences() {
|
||||
|
||||
@@ -1,8 +1,32 @@
|
||||
package de.rayzs.pat.utils.message;
|
||||
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public interface Translator {
|
||||
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
String translate(String text);
|
||||
|
||||
void send(Object target, String text);
|
||||
|
||||
void sendActionbar(Object target, String text);
|
||||
|
||||
void sendTitle(Object target, String title, String subtitle, int fadeIn, int stay, int fadeOut);
|
||||
|
||||
void playSound(Object target, String soundKey, float volume, float pitch) throws Exception;
|
||||
|
||||
default Component toComponent(String text) {
|
||||
text = StringUtils.replace(text, "§", "&");
|
||||
|
||||
Component legacy = LegacyComponentSerializer.legacyAmpersand().deserialize(text);
|
||||
text = StringUtils.replace(miniMessage.serialize(legacy), "\\", "");
|
||||
|
||||
return miniMessage.deserialize(text);
|
||||
}
|
||||
|
||||
void close();
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
package de.rayzs.pat.utils.message.translators;
|
||||
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import de.rayzs.pat.utils.message.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class BukkitMessageTranslator implements Translator {
|
||||
|
||||
private BukkitAudiences audiences;
|
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
public BukkitMessageTranslator() {
|
||||
audiences = BukkitAudiences.create(BukkitLoader.getPlugin());
|
||||
@@ -26,9 +27,34 @@ public class BukkitMessageTranslator implements Translator {
|
||||
@Override
|
||||
public void send(Object target, String text) {
|
||||
Audience audience = target instanceof Player ? audiences.player((Player) target) : audiences.sender((CommandSender) target);
|
||||
text = this.miniMessage.serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(text.replace("§", "&")));
|
||||
if(text.contains("\\")) text = text.replace("\\", "");
|
||||
audience.sendMessage(this.miniMessage.deserialize(text));
|
||||
|
||||
audience.sendMessage(toComponent(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionbar(Object target, String text) {
|
||||
Audience audience = target instanceof Player ? audiences.player((Player) target) : audiences.sender((CommandSender) target);
|
||||
|
||||
audience.sendActionBar(toComponent(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(Object target, String titleStr, String subtitleStr, int fadeIn, int stay, int fadeOut) {
|
||||
Audience audience = target instanceof Player ? audiences.player((Player) target) : audiences.sender((CommandSender) target);
|
||||
|
||||
Title.Times times = Title.Times.times(Duration.ofMillis(fadeIn), Duration.ofMillis(stay), Duration.ofMillis(fadeOut));
|
||||
Title title = Title.title(toComponent(titleStr), toComponent(subtitleStr), times);
|
||||
|
||||
audience.showTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Object target, String soundKey, float volume, float pitch) throws Exception {
|
||||
if (target instanceof Player player) {
|
||||
Sound sound = Sound.valueOf(soundKey);
|
||||
|
||||
player.playSound(player.getLocation(), sound, volume, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package de.rayzs.pat.utils.message.translators;
|
||||
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
@@ -10,10 +13,11 @@ import de.rayzs.pat.utils.message.Translator;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class BungeeMessageTranslator implements Translator {
|
||||
|
||||
private BungeeAudiences audiences;
|
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
public BungeeMessageTranslator() {
|
||||
audiences = BungeeAudiences.create(BungeeLoader.getPlugin());
|
||||
@@ -27,9 +31,33 @@ public class BungeeMessageTranslator implements Translator {
|
||||
@Override
|
||||
public void send(Object target, String text) {
|
||||
Audience audience = target instanceof ProxiedPlayer ? audiences.player((ProxiedPlayer) target) : audiences.sender((CommandSender) target);
|
||||
text = this.miniMessage.serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(text.replace("§", "&")));
|
||||
if(text.contains("\\")) text = text.replace("\\", "");
|
||||
audience.sendMessage(this.miniMessage.deserialize(text));
|
||||
|
||||
audience.sendMessage(toComponent(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionbar(Object target, String text) {
|
||||
Audience audience = target instanceof ProxiedPlayer ? audiences.player((ProxiedPlayer) target) : audiences.sender((CommandSender) target);
|
||||
|
||||
audience.sendActionBar(toComponent(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(Object target, String titleStr, String subtitleStr, int fadeIn, int stay, int fadeOut) {
|
||||
Audience audience = target instanceof ProxiedPlayer ? audiences.player((ProxiedPlayer) target) : audiences.sender((CommandSender) target);
|
||||
|
||||
Title.Times times = Title.Times.times(Duration.ofMillis(fadeIn), Duration.ofMillis(stay), Duration.ofMillis(fadeOut));
|
||||
Title title = Title.title(toComponent(titleStr), toComponent(subtitleStr), times);
|
||||
|
||||
audience.showTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Object target, String soundKey, float volume, float pitch) throws Exception {
|
||||
Audience audience = target instanceof ProxiedPlayer ? audiences.player((ProxiedPlayer) target) : audiences.sender((CommandSender) target);
|
||||
Sound sound = Sound.sound(Key.key(soundKey), Sound.Source.MASTER, 1f, 1f);
|
||||
|
||||
audience.playSound(sound, Sound.Emitter.self());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+34
-15
@@ -1,33 +1,52 @@
|
||||
package de.rayzs.pat.utils.message.translators;
|
||||
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import com.velocitypowered.api.proxy.*;
|
||||
import de.rayzs.pat.utils.message.*;
|
||||
import net.kyori.adventure.title.Title;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class VelocityMessageTranslator implements Translator {
|
||||
|
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
@Override
|
||||
public String translate(String text) {
|
||||
return miniMessage.serialize(miniMessage.deserialize(MessageTranslator.translateLegacy(text)));
|
||||
return MiniMessage.miniMessage().serialize(miniMessage.deserialize(MessageTranslator.translateLegacy(text)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object target, String text) {
|
||||
text = this.miniMessage.serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(text.replace("§", "&")));
|
||||
if(text.contains("\\")) text = text.replace("\\", "");
|
||||
final Component component = this.miniMessage.deserialize(text);
|
||||
if (target instanceof CommandSource source) {
|
||||
source.sendMessage(toComponent(text));
|
||||
}
|
||||
}
|
||||
|
||||
if(target instanceof Player)
|
||||
((Player) target).sendMessage(component);
|
||||
else if(target instanceof CommandSource)
|
||||
((ConsoleCommandSource) target).sendMessage(component);
|
||||
else if(target instanceof ConsoleCommandSource)
|
||||
((ConsoleCommandSource) target).sendMessage(component);
|
||||
@Override
|
||||
public void sendActionbar(Object target, String text) {
|
||||
if (target instanceof CommandSource source) {
|
||||
source.sendActionBar(toComponent(text));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(Object target, String titleStr, String subtitleStr, int fadeIn, int stay, int fadeOut) {
|
||||
Title.Times times = Title.Times.times(Duration.ofMillis(fadeIn), Duration.ofMillis(stay), Duration.ofMillis(fadeOut));
|
||||
Title title = Title.title(toComponent(titleStr), toComponent(subtitleStr), times);
|
||||
|
||||
if (target instanceof CommandSource source) {
|
||||
source.showTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Object target, String soundKey, float volume, float pitch) throws Exception {
|
||||
if (target instanceof CommandSource source) {
|
||||
Sound sound = Sound.sound(Key.key(soundKey), Sound.Source.MASTER, 1f, 1f);
|
||||
|
||||
source.playSound(sound, Sound.Emitter.self());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
package de.rayzs.pat.utils.node;
|
||||
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
public class BukkitCommandNodeHelper {
|
||||
|
||||
private final List<SimpleNode> nodeList = new ArrayList<>();
|
||||
private final Object packetObj;
|
||||
private final List entries;
|
||||
private final Node root;
|
||||
|
||||
public BukkitCommandNodeHelper(Object packetObj) throws Exception {
|
||||
this.packetObj = packetObj;
|
||||
|
||||
final Class<?> commandsPacketClazz = packetObj.getClass();
|
||||
final Field rootIndexField = commandsPacketClazz.getDeclaredField("rootIndex");
|
||||
rootIndexField.setAccessible(true);
|
||||
|
||||
final int rootIndex = rootIndexField.getInt(packetObj);
|
||||
rootIndexField.setAccessible(false);
|
||||
|
||||
|
||||
final Field entriesField = commandsPacketClazz.getDeclaredField("entries");
|
||||
entriesField.setAccessible(true);
|
||||
|
||||
entries = (List) entriesField.get(packetObj);
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
final Object nodeObj = entries.get(i);
|
||||
final Class<?> entryClass = nodeObj.getClass();
|
||||
final Field nodeChildrenField = entryClass.getDeclaredField("children");
|
||||
nodeChildrenField.setAccessible(true);
|
||||
|
||||
|
||||
int[] children = (int[]) nodeChildrenField.get(nodeObj);
|
||||
nodeChildrenField.setAccessible(false);
|
||||
|
||||
|
||||
final Field stubField = entryClass.getDeclaredField("stub");
|
||||
stubField.setAccessible(true);
|
||||
|
||||
String name = null;
|
||||
|
||||
final Object stubObj = stubField.get(nodeObj);
|
||||
if (stubObj != null) {
|
||||
final Class<?> stubClass = stubObj.getClass();
|
||||
final Field idField = stubClass.getDeclaredField("id");
|
||||
idField.setAccessible(true);
|
||||
|
||||
name = idField.get(stubObj).toString();
|
||||
|
||||
idField.setAccessible(false);
|
||||
}
|
||||
|
||||
stubField.setAccessible(false);
|
||||
|
||||
final SimpleNode simpleNode = new SimpleNode(rootIndex, i, children, name);
|
||||
nodeList.add(simpleNode);
|
||||
}
|
||||
|
||||
root = createRootNode(this, rootIndex, nodeList.toArray(new SimpleNode[0]));
|
||||
}
|
||||
|
||||
public void removeSubArguments(String command) throws Exception {
|
||||
final String[] args = command.split(" ");
|
||||
final Node child = getRoot().getChild(args[0]);
|
||||
|
||||
removeSubArguments(child, 0, args);
|
||||
}
|
||||
|
||||
public void spareRecursively(List<String> spares) throws Exception {
|
||||
final Set<String> sparesSet = new HashSet<>(spares.stream().map(StringUtils::getFirstArg).toList());
|
||||
|
||||
for (String childName : sparesSet) {
|
||||
Node child = root.getChild(childName);
|
||||
if (child != null) {
|
||||
spareRecursively(child.getName(), child, spares);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void spareRecursively(String str, Node parent, List<String> spares) throws Exception {
|
||||
final List<Node> children = new ArrayList<>(parent.getChildren());
|
||||
|
||||
if (!parent.isRoot() && children.size() == 1) {
|
||||
final Node firstChild = children.get(0);
|
||||
|
||||
if (firstChild.getName() != null && firstChild.getName().equalsIgnoreCase("args")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (final Node child : children) {
|
||||
final String command = str + " " + child.getName();
|
||||
final String[] commandArgs = command.split(" ");
|
||||
|
||||
boolean found = false;
|
||||
for (String spare : spares) {
|
||||
final String[] spareArgs = spare.split(" ");
|
||||
|
||||
if (!spareArgs[0].equals(commandArgs[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean match = true;
|
||||
for (int i = 1; i < spareArgs.length; i++) {
|
||||
final String s = spareArgs[i];
|
||||
|
||||
if (commandArgs.length - 1 < i) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (commandArgs.length - 1 == i && s.equals("_-")) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (s.startsWith("%") && s.endsWith("%")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!s.equals(commandArgs[i])) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (match) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
parent.removeChild(child);
|
||||
} else {
|
||||
spareRecursively(command, child, spares);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeSubArguments(Node parent, int index, String[] args) throws Exception {
|
||||
final int max = args.length - 1;
|
||||
final int nextIndex = index + 1;
|
||||
|
||||
if (parent == null || index > max || nextIndex > max) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String nextPart = args[nextIndex];
|
||||
|
||||
if (nextIndex == max) {
|
||||
parent.removeChild(nextPart);
|
||||
return;
|
||||
}
|
||||
|
||||
final Node nextParent = parent.getChild(nextPart);
|
||||
if (nextParent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeSubArguments(nextParent, nextIndex + 1, args);
|
||||
}
|
||||
|
||||
public Node getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
private Object createEmptyEntry() throws Exception {
|
||||
final String path = packetObj.getClass().getPackage().getName() + "." + packetObj.getClass().getSimpleName();
|
||||
|
||||
final String literalNodeStubPath = path + "$LiteralNodeStub";
|
||||
final String entryPath = path + "$Entry";
|
||||
final String nodeStubPath = path + "$NodeStub";
|
||||
|
||||
final int[] children = {};
|
||||
|
||||
final Class<?> nodeStubClazz = Class.forName(nodeStubPath);
|
||||
|
||||
final Class<?> literalNodeClazz = Class.forName(literalNodeStubPath);
|
||||
final Constructor<?> literalNodeConstructor = literalNodeClazz.getDeclaredConstructor(String.class);
|
||||
literalNodeConstructor.setAccessible(true);
|
||||
|
||||
final Object literalNodeObj = literalNodeConstructor.newInstance("");
|
||||
|
||||
final Class<?> entryClazz = Class.forName(entryPath);
|
||||
final Constructor<?> entryConstructor = entryClazz.getDeclaredConstructor(nodeStubClazz, int.class, int.class, int[].class);
|
||||
entryConstructor.setAccessible(true);
|
||||
|
||||
final Object entryObj = entryConstructor.newInstance(literalNodeObj, 1, 0, children);
|
||||
|
||||
|
||||
literalNodeConstructor.setAccessible(false);
|
||||
entryConstructor.setAccessible(false);
|
||||
|
||||
|
||||
return entryObj;
|
||||
}
|
||||
|
||||
private Node createRootNode(BukkitCommandNodeHelper process, int rootIndex, final SimpleNode[] nodes) {
|
||||
return new Node(process, nodes[rootIndex], nodes);
|
||||
}
|
||||
|
||||
private static class Node {
|
||||
|
||||
private final int rootIndex, index;
|
||||
private final List<Node> children;
|
||||
private final SimpleNode simpleNode;
|
||||
private final BukkitCommandNodeHelper process;
|
||||
|
||||
@Nullable
|
||||
private final String name;
|
||||
|
||||
public Node(BukkitCommandNodeHelper process, SimpleNode node, final SimpleNode[] nodes) {
|
||||
this.process = process;
|
||||
this.simpleNode = node;
|
||||
|
||||
this.rootIndex = node.rootIndex;
|
||||
this.index = node.index;
|
||||
|
||||
this.name = node.name;
|
||||
this.children = new ArrayList<>();
|
||||
|
||||
if (!node.isRoot() && name == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int childIndex : node.children()) {
|
||||
final Node child = new Node(process, nodes[childIndex], nodes);
|
||||
this.children.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeChild(int childIndex) throws Exception {
|
||||
final Node child = getChild(childIndex);
|
||||
|
||||
if (child != null) {
|
||||
this.children.remove(child);
|
||||
this.process.entries.set(child.index, this.process.createEmptyEntry());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeChild(Node child) throws Exception {
|
||||
if (child != null) {
|
||||
this.children.remove(child);
|
||||
this.process.entries.set(child.index, this.process.createEmptyEntry());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeChild(String childName) throws Exception {
|
||||
final Node child = getChild(childName);
|
||||
|
||||
if (child != null) {
|
||||
this.children.remove(child);
|
||||
this.process.entries.set(child.index, this.process.createEmptyEntry());
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleNode getSimpleNode() {
|
||||
return simpleNode;
|
||||
}
|
||||
|
||||
public int getRootIndex() {
|
||||
return rootIndex;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
return index == rootIndex;
|
||||
}
|
||||
|
||||
public List<Node> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public Node getChild(int index) {
|
||||
return children.get(index);
|
||||
}
|
||||
|
||||
public Node getChild(String name) {
|
||||
return this.children.stream().filter(n -> n.getName() != null && n.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public @Nullable String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private record SimpleNode(int rootIndex, int index, int[] children, @Nullable String name) {
|
||||
public boolean isRoot() {
|
||||
return index == rootIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
-23
@@ -7,15 +7,16 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.tree.*;
|
||||
import net.md_5.bungee.protocol.packet.Commands;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandNodeHelper<T> {
|
||||
public class ProxyCommandNodeHelper<T> {
|
||||
|
||||
private static final Command DUMMY_COMMAND = (context) -> 0;
|
||||
|
||||
private static SuggestionProvider DEFAULT_SUGGESTION_PROVIDER;
|
||||
|
||||
public static void setDefaultSuggestionProvider(SuggestionProvider<?> suggestionProvider) {
|
||||
@@ -45,7 +46,7 @@ public class CommandNodeHelper<T> {
|
||||
|
||||
private final RootCommandNode<T> rootNode;
|
||||
|
||||
public CommandNodeHelper(RootCommandNode<T> rootNode) {
|
||||
public ProxyCommandNodeHelper(RootCommandNode<T> rootNode) {
|
||||
this.rootNode = rootNode;
|
||||
}
|
||||
|
||||
@@ -53,7 +54,7 @@ public class CommandNodeHelper<T> {
|
||||
return rootNode.getChildren().stream().map(CommandNode::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public CommandNodeHelper<T> removeIf(CommandNode<T> node, Predicate<String> predicate) {
|
||||
public ProxyCommandNodeHelper<T> removeIf(CommandNode<T> node, Predicate<String> predicate) {
|
||||
if (node != null && node.getRedirect() != null)
|
||||
node = node.getRedirect();
|
||||
|
||||
@@ -64,6 +65,7 @@ public class CommandNodeHelper<T> {
|
||||
continue;
|
||||
|
||||
String name = n.getName();
|
||||
|
||||
if (predicate.test(name)) {
|
||||
objs.add(n);
|
||||
}
|
||||
@@ -76,21 +78,21 @@ public class CommandNodeHelper<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNodeHelper<T> removeIf(String childName, Predicate<String> predicate) {
|
||||
public ProxyCommandNodeHelper<T> removeIf(String childName, Predicate<String> predicate) {
|
||||
CommandNode<T> node = rootNode.getChild(childName);
|
||||
return removeIf(node, predicate);
|
||||
}
|
||||
|
||||
public CommandNodeHelper<T> removeIf(Predicate<String> predicate) {
|
||||
public ProxyCommandNodeHelper<T> removeIf(Predicate<String> predicate) {
|
||||
return removeIf(rootNode, predicate);
|
||||
}
|
||||
|
||||
public CommandNodeHelper<T> clear() {
|
||||
public ProxyCommandNodeHelper<T> clear() {
|
||||
rootNode.getChildren().clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNodeHelper<T> clear(String childName) {
|
||||
public ProxyCommandNodeHelper<T> clear(String childName) {
|
||||
CommandNode child = rootNode.getChild(childName);
|
||||
|
||||
if (child != null) {
|
||||
@@ -101,39 +103,74 @@ public class CommandNodeHelper<T> {
|
||||
}
|
||||
|
||||
|
||||
public CommandNodeHelper<T> remove(Object obj) {
|
||||
public ProxyCommandNodeHelper<T> remove(Object obj) {
|
||||
rootNode.getChildren().remove(obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNodeHelper<T> remove(CommandNode node, Object obj) {
|
||||
public ProxyCommandNodeHelper<T> remove(CommandNode node, Object obj) {
|
||||
node.getChildren().remove(obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNodeHelper<T> add(String commandPath, boolean autoSuggestions) {
|
||||
String[] args = commandPath.split(" ");
|
||||
add(rootNode, args, 0, autoSuggestions);
|
||||
public ProxyCommandNodeHelper<T> add(String original, boolean autoSuggestions) {
|
||||
String[] args = original.split(" ");
|
||||
add(original, rootNode, args, 0, autoSuggestions);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void add(CommandNode<T> parent, String[] args, int index, boolean autoSuggestions) {
|
||||
public ProxyCommandNodeHelper<T> removeSubArguments(String original) {
|
||||
String[] args = original.split(" ");
|
||||
removeSubArguments(rootNode, args, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void removeSubArguments(CommandNode<T> parent, String[] args, int index) {
|
||||
if (index >= args.length) return;
|
||||
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String part = args[index];
|
||||
CommandNode<T> childNode = parent.getChild(part);
|
||||
|
||||
if (index == (args.length - 1)) {
|
||||
parent.getChildren().remove(childNode);
|
||||
return;
|
||||
}
|
||||
|
||||
removeSubArguments(childNode, args, index + 1);
|
||||
}
|
||||
|
||||
private void add(final String original, CommandNode<T> parent, String[] args, int index, boolean autoSuggestions) {
|
||||
if (index >= args.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
String part = args[index];
|
||||
|
||||
if (index == 0) {
|
||||
part = Storage.Blacklist.BlockTypeFetcher.modify(Storage.Blacklist.BlockTypeFetcher.modify(part));
|
||||
}
|
||||
|
||||
if (part.length() > 1 && part.startsWith("%") && part.endsWith("%")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String next = index + 1 >= args.length ? null : args[index + 1];
|
||||
CommandNode<T> childNode = parent.getChild(part);
|
||||
|
||||
if (original.charAt(0) == '!' && index == (args.length - 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (childNode == null) {
|
||||
LiteralCommandNode newNode;
|
||||
|
||||
boolean cancel = next != null && (next.equals("_-"));
|
||||
boolean stop = next != null && next.startsWith("%") && next.endsWith("%");
|
||||
boolean skip = part.equals("-_");
|
||||
|
||||
if (index == 0 && part.charAt(0) == '!' && part.length() > 1) {
|
||||
return;
|
||||
}
|
||||
final boolean cancel = next != null && (next.equals("_-"));
|
||||
final boolean stop = next != null && next.startsWith("%") && next.endsWith("%");
|
||||
final boolean skip = part.equals("-_");
|
||||
|
||||
if (skip) {
|
||||
return;
|
||||
@@ -148,7 +185,7 @@ public class CommandNodeHelper<T> {
|
||||
newNode = LiteralArgumentBuilder.literal(part)
|
||||
.then(RequiredArgumentBuilder
|
||||
.argument("args", (ArgumentType) StringArgumentType.greedyString())
|
||||
.suggests(Commands.SuggestionRegistry.ASK_SERVER))
|
||||
.suggests(DEFAULT_SUGGESTION_PROVIDER))
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -161,6 +198,6 @@ public class CommandNodeHelper<T> {
|
||||
childNode = newNode;
|
||||
}
|
||||
|
||||
add(childNode, args, index + 1, autoSuggestions);
|
||||
add(original, childNode, args, index + 1, autoSuggestions);
|
||||
}
|
||||
}
|
||||
@@ -31,17 +31,11 @@ public class PermissionUtil {
|
||||
|
||||
resetPermissions(uuid);
|
||||
setPlayerPermissions(uuid);
|
||||
|
||||
CommandSender sender = CommandSenderHandler.getSenderFromUUID(uuid);
|
||||
if (sender != null) {
|
||||
sender.updateGroups();
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadPermissions(CommandSender sender) {
|
||||
resetPermissions(sender.getUniqueId());
|
||||
setPlayerPermissions(sender);
|
||||
sender.updateGroups();
|
||||
}
|
||||
|
||||
public static String getPermissionsAsString(UUID uuid) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.rayzs.pat.utils.response;
|
||||
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.plugin.subarguments.SubArguments;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
@@ -25,63 +26,92 @@ public class ResponseHandler {
|
||||
}
|
||||
|
||||
public static String replaceArgsVariables(String input, String command) {
|
||||
final String[] commandSplit = command.contains(" ") ? command.split(" ") : new String[] { command };
|
||||
final String[] inputSplit = input.contains(" ") ? input.split(" ") : new String[] { input };
|
||||
try {
|
||||
final char[] chars = input.toCharArray();
|
||||
final String placeholder = "%args[";
|
||||
|
||||
final StringBuilder output = new StringBuilder();
|
||||
final int commandLength = commandSplit.length;
|
||||
int index = -1;
|
||||
int found = 0;
|
||||
|
||||
for (int i = 0; i < inputSplit.length; i++) {
|
||||
String part = inputSplit[i];
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
final char c = chars[i];
|
||||
|
||||
if (i > 0) {
|
||||
output.append(" ");
|
||||
}
|
||||
if (c != placeholder.charAt(found)) {
|
||||
if (found > 0) {
|
||||
i--;
|
||||
}
|
||||
|
||||
if (! (part.startsWith("%args[") && part.endsWith("]%"))) {
|
||||
output.append(part);
|
||||
continue;
|
||||
}
|
||||
|
||||
part = part.substring(part.indexOf('[') + 1, part.lastIndexOf(']'));
|
||||
|
||||
int fromIndex, toIndex;
|
||||
|
||||
try {
|
||||
if (part.contains("-")) {
|
||||
final String[] partSplit = part.split("-");
|
||||
fromIndex = Integer.parseInt(partSplit[0]);
|
||||
toIndex = Integer.parseInt(partSplit[1]);
|
||||
} else if (part.startsWith("_")) {
|
||||
final String[] partSplit = part.split("_");
|
||||
fromIndex = 0;
|
||||
toIndex = Integer.parseInt(partSplit[1]);
|
||||
} else if (part.endsWith("_")) {
|
||||
final String[] partSplit = part.split("_");
|
||||
fromIndex = Integer.parseInt(partSplit[0]);
|
||||
toIndex = commandLength + 1;
|
||||
} else {
|
||||
fromIndex = Integer.parseInt(part);
|
||||
toIndex = fromIndex;
|
||||
found = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
fromIndex = Math.max(0, fromIndex - 1);
|
||||
toIndex = Math.min(commandLength, toIndex);
|
||||
found++;
|
||||
|
||||
output.append(String.join(" ", Arrays.copyOfRange(commandSplit, fromIndex, toIndex)));
|
||||
} catch (NumberFormatException exception) {
|
||||
Logger.warning("Failed to convert number! (" + part + ")");
|
||||
if (found == placeholder.length()) {
|
||||
index = i - placeholder.length() + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == -1) {
|
||||
return input;
|
||||
}
|
||||
|
||||
String argument = input.substring(index);
|
||||
final int endIndex = argument.substring(2).indexOf(']');
|
||||
|
||||
if (endIndex != -1) {
|
||||
argument = argument.substring(0, endIndex + 4);
|
||||
|
||||
String[] commandSplit = command.split(" ");
|
||||
|
||||
final String argumentInsides = argument.substring(6, argument.length() - 2);
|
||||
int leftNum = -1, rightNum = -1;
|
||||
|
||||
if (argumentInsides.contains("-")) {
|
||||
final String[] numSplit = argumentInsides.split("-");
|
||||
|
||||
leftNum = Integer.parseInt(numSplit[0]);
|
||||
rightNum = Integer.parseInt(numSplit[1]);
|
||||
} else if (argumentInsides.startsWith("_")) {
|
||||
leftNum = 0;
|
||||
rightNum = Integer.parseInt(argumentInsides.replace("_", ""));
|
||||
} else if (argumentInsides.endsWith("_")) {
|
||||
leftNum = Integer.parseInt(argumentInsides.replace("_", ""));
|
||||
rightNum = commandSplit.length;
|
||||
}
|
||||
|
||||
final StringBuilder replacementCommand = new StringBuilder();
|
||||
|
||||
if (leftNum == -1 && rightNum == -1) {
|
||||
final int i = Integer.parseInt(argumentInsides) - 1;
|
||||
replacementCommand.append(commandSplit[Math.min(commandSplit.length - 1, i)]);
|
||||
} else {
|
||||
final int min = Math.max(0, leftNum + -1);
|
||||
final int max = Math.min(rightNum, commandSplit.length);
|
||||
|
||||
for (int i = min; i < max; i++) {
|
||||
if (i != min) replacementCommand.append(" ");
|
||||
replacementCommand.append(commandSplit[i]);
|
||||
}
|
||||
}
|
||||
|
||||
input = input.substring(0, index) + replacementCommand + input.substring(index + endIndex + 4);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
Logger.warning("Failed to parse and replace %args[...]% parts. Please make sure that the format is correct and that befitting the written numbers.");
|
||||
Logger.warning("Check examples from the custom-responses.yml file for comparison.");
|
||||
return input;
|
||||
}
|
||||
|
||||
return output.toString();
|
||||
return replaceArgsVariables(input, command);
|
||||
}
|
||||
|
||||
public static List<String> getResponse(UUID uuid, String input) {
|
||||
return getResponse(uuid, input, Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE.getLines());
|
||||
public static List<String> getResponse(UUID uuid, String playerName, String serverName, String input) {
|
||||
return getResponse(uuid, playerName, serverName, input, Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE.getLines());
|
||||
}
|
||||
|
||||
public static List<String> getResponse(UUID uuid, String input, List<String> defaultMessage) {
|
||||
public static List<String> getResponse(UUID uuid, String playerName, String serverName, String input, List<String> defaultMessage) {
|
||||
final String finalInput = input.startsWith("/") && input.length() > 1
|
||||
? input.substring(1)
|
||||
: input;
|
||||
@@ -95,7 +125,7 @@ public class ResponseHandler {
|
||||
}).findFirst();
|
||||
|
||||
if (uuid != null && optionalResponse.isPresent()) {
|
||||
optionalResponse.get().executeAction(uuid, finalInput);
|
||||
optionalResponse.get().executeAction(uuid, playerName, serverName, finalInput);
|
||||
|
||||
return new ArrayList<>(optionalResponse.get().message)
|
||||
.stream().map(s -> replaceArgsVariables(s, finalInput))
|
||||
@@ -111,14 +141,20 @@ public class ResponseHandler {
|
||||
|
||||
public Response(final String key) {
|
||||
this.triggers = (List<String>) Storage.Files.CUSTOM_RESPONSES.get(key + ".triggers");
|
||||
this.message = (List<String>) Storage.Files.CUSTOM_RESPONSES.getOrSet(key + ".message", SubArgsModule.BLOCKED_MESSAGE);
|
||||
this.message = (List<String>) Storage.Files.CUSTOM_RESPONSES.getOrSet(key + ".message", SubArguments.BLOCKED_MESSAGE);
|
||||
this.actions = (List<String>) Storage.Files.CUSTOM_RESPONSES.getOrSet(key + ".actions", new ArrayList<>());
|
||||
}
|
||||
|
||||
public void executeAction(UUID uuid, String command) {
|
||||
public void executeAction(UUID uuid, String playerName, String serverName, String command) {
|
||||
String[] split;
|
||||
|
||||
for (String action : actions) {
|
||||
|
||||
if (action.equals("alert")) {
|
||||
ActionHandler.alert(uuid, playerName, serverName, command);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!action.contains("::")) {
|
||||
Logger.warning("! Could not recognise action: " + action);
|
||||
Logger.warning(" > Syntax does not match at all. Have you used the splitters (::) correctly?");
|
||||
@@ -205,19 +241,12 @@ public class ResponseHandler {
|
||||
continue;
|
||||
|
||||
case "sound":
|
||||
|
||||
if (Reflection.isProxyServer()) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Sounds cannot be played on the proxy side!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (split.length != 4) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Action requires 4 arguments but only has " + split.length);
|
||||
Logger.warning(" > Here's an example to compare with:");
|
||||
Logger.warning(" > sound::soundName::volume::pitch");
|
||||
Logger.warning(" > e.g: sound::ENTITY_ENDER_DRAGON_GROWL::1.0::1.0");
|
||||
Logger.warning(" > e.g: sound::" + (Reflection.isProxyServer() ? "entity.ender_dragon.growl:" : "ENTITY_ENDER_DRAGON_GROWL") + "::1.0::1.0");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -225,6 +254,13 @@ public class ResponseHandler {
|
||||
|
||||
try {
|
||||
volume = Float.parseFloat(split[2]);
|
||||
|
||||
if (volume < 0 || volume > 10) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Your volume (" + split[2].toUpperCase() + ") must be between 0.0 and 10.0! (e.g: 1.0)");
|
||||
continue;
|
||||
}
|
||||
|
||||
} catch (Exception exception) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Volume " + split[2].toUpperCase() + " is not a valid float! (e.g: 1.0f)");
|
||||
@@ -233,13 +269,26 @@ public class ResponseHandler {
|
||||
|
||||
try {
|
||||
pitch = Float.parseFloat(split[3]);
|
||||
|
||||
if (pitch < 0 || pitch > 10) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Your pitch (" + split[2].toUpperCase() + ") must be between 0.0 and 2.0! (e.g: 1.0)");
|
||||
continue;
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Pitch " + split[3].toUpperCase() + " is not a valid float! (e.g: 1.0f)");
|
||||
Logger.warning(" > Pitch " + split[3].toUpperCase() + " is not a valid float! (e.g: 1.0)");
|
||||
continue;
|
||||
}
|
||||
|
||||
ActionHandler.playSound(action, uuid, split[1].toUpperCase(), volume, pitch);
|
||||
ActionHandler.playSound(
|
||||
action,
|
||||
uuid,
|
||||
Reflection.isProxyServer() ? split[1].toLowerCase() : split[1].toUpperCase(),
|
||||
volume,
|
||||
pitch
|
||||
);
|
||||
|
||||
continue;
|
||||
|
||||
case "console":
|
||||
@@ -249,9 +298,11 @@ public class ResponseHandler {
|
||||
Logger.warning(" > Here's an example to compare with:");
|
||||
Logger.warning(" > console::command");
|
||||
Logger.warning(" > e.g: console::say Hello world!");
|
||||
continue;
|
||||
}
|
||||
|
||||
ActionHandler.executeConsoleCommand(action, uuid, command, split[1]);
|
||||
continue;
|
||||
|
||||
case "execute":
|
||||
if (split.length == 1) {
|
||||
@@ -260,9 +311,11 @@ public class ResponseHandler {
|
||||
Logger.warning(" > Here's an example to compare with:");
|
||||
Logger.warning(" > execute::command");
|
||||
Logger.warning(" > e.g: execute::help");
|
||||
continue;
|
||||
}
|
||||
|
||||
ActionHandler.executePlayerCommand(action, uuid, command, split[1]);
|
||||
continue;
|
||||
|
||||
case "actionbar":
|
||||
if (split.length == 1) {
|
||||
@@ -271,9 +324,114 @@ public class ResponseHandler {
|
||||
Logger.warning(" > Here's an example to compare with:");
|
||||
Logger.warning(" > actionbar::text");
|
||||
Logger.warning(" > e.g: actionbar::I like COOKIES");
|
||||
continue;
|
||||
}
|
||||
|
||||
ActionHandler.sendActionbar(action, uuid, command, split[1]);
|
||||
continue;
|
||||
|
||||
case "p2b-message":
|
||||
|
||||
if (!Reflection.isProxyServer()) {
|
||||
Logger.warning("! Could not execute action: " + action);
|
||||
Logger.warning(" > Cannot send p2b-packets on a backend server!");
|
||||
Logger.warning(" > This only works on proxy servers!");
|
||||
Logger.warning(" > P2B -> Proxy to Backend");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (serverName == null) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Failed to fetch servername player is on!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (split.length == 1) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Action requires 1 arguments but only has " + split.length);
|
||||
Logger.warning(" > Here's an example to compare with:");
|
||||
Logger.warning(" > p2b-message::text");
|
||||
Logger.warning(" > e.g: p2b-message::&cUser %player% is evil!");
|
||||
continue;
|
||||
}
|
||||
|
||||
Communicator.Proxy2Backend.sendConsoleMessage(
|
||||
serverName,
|
||||
ResponseHandler.replaceArgsVariables(
|
||||
StringUtils.replace(split[1], "%player%", playerName),
|
||||
command
|
||||
)
|
||||
);
|
||||
continue;
|
||||
|
||||
case "p2b-execute":
|
||||
|
||||
if (!Reflection.isProxyServer()) {
|
||||
Logger.warning("! Could not execute action: " + action);
|
||||
Logger.warning(" > Cannot send p2b-packets on a backend server!");
|
||||
Logger.warning(" > This only works on proxy servers!");
|
||||
Logger.warning(" > P2B -> Proxy to Backend");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (serverName == null) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Failed to fetch servername player is on!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (split.length == 1) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Action requires 1 arguments but only has " + split.length);
|
||||
Logger.warning(" > Here's an example to compare with:");
|
||||
Logger.warning(" > p2b-execute::command");
|
||||
Logger.warning(" > e.g: p2b-execute::help");
|
||||
continue;
|
||||
}
|
||||
|
||||
Communicator.Proxy2Backend.sendExecutePlayerCommand(
|
||||
serverName,
|
||||
uuid,
|
||||
ResponseHandler.replaceArgsVariables(
|
||||
StringUtils.replace(split[1], "%player%", playerName),
|
||||
command
|
||||
)
|
||||
);
|
||||
|
||||
continue;
|
||||
|
||||
case "p2b-console":
|
||||
|
||||
if (!Reflection.isProxyServer()) {
|
||||
Logger.warning("! Could not execute action: " + action);
|
||||
Logger.warning(" > Cannot send p2b-packets on a backend server!");
|
||||
Logger.warning(" > This only works on proxy servers!");
|
||||
Logger.warning(" > P2B -> Proxy to Backend");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (serverName == null) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Failed to fetch servername player is on!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (split.length == 1) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > Action requires 1 arguments but only has " + split.length);
|
||||
Logger.warning(" > Here's an example to compare with:");
|
||||
Logger.warning(" > p2b-console::command");
|
||||
Logger.warning(" > e.g: p2b-console::help");
|
||||
continue;
|
||||
}
|
||||
|
||||
Communicator.Proxy2Backend.sendExecuteConsoleCommand(
|
||||
serverName,
|
||||
ResponseHandler.replaceArgsVariables(
|
||||
StringUtils.replace(split[1], "%player%", playerName),
|
||||
command
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package de.rayzs.pat.utils.response.action;
|
||||
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface Action {
|
||||
@@ -11,4 +18,29 @@ public interface Action {
|
||||
void playSound(String action, UUID uuid, String soundName, float volume, float pitch);
|
||||
void sendActionbar(String action, UUID uuid, String command, String message);
|
||||
|
||||
default void alert(UUID uuid, String playerName, String serverName, String command) {
|
||||
command = command.startsWith("/") ? command.substring(1) : command;
|
||||
command = StringUtils.getFirstArg(command);
|
||||
|
||||
final String displayCommand = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
|
||||
final List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
Storage.ConfigSections.Messages.NOTIFICATION.ALERT,
|
||||
"%player%", playerName,
|
||||
"%command%", displayCommand,
|
||||
"%server%", serverName);
|
||||
|
||||
Communicator.Proxy2Backend.sendNotification(uuid, serverName, displayCommand);
|
||||
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
Logger.info(notificationMessage);
|
||||
|
||||
Storage.NOTIFY_PLAYERS.stream().forEach(tmpUUID -> {
|
||||
Object p = Storage.getLoader().getPlayerObjByUUID(tmpUUID);
|
||||
if (p != null) {
|
||||
MessageTranslator.send(p, notificationMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public class ActionHandler {
|
||||
|
||||
private static final Action ACTION = Reflection.isProxyServer() ? Reflection.isVelocityServer()
|
||||
? new VelocityAction() : new BungeeAction()
|
||||
: Reflection.getMinor() <= 16
|
||||
: Reflection.isAtMost(1, 16)
|
||||
? new OldBukkitAction() : new ModernBukkitAction();
|
||||
|
||||
public static void initialize() {}
|
||||
@@ -36,4 +36,8 @@ public class ActionHandler {
|
||||
public static void sendActionbar(String action, UUID uuid, String command, String message) {
|
||||
ACTION.sendActionbar(action, uuid, command, message);
|
||||
}
|
||||
|
||||
public static void alert(UUID uuid, String playerName, String serverName, String command) {
|
||||
ACTION.alert(uuid, playerName, serverName, command);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,10 @@ package de.rayzs.pat.utils.response.action.impl;
|
||||
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import de.rayzs.pat.utils.response.action.Action;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.Title;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -19,8 +17,9 @@ public class BungeeAction implements Action {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (player != null)
|
||||
if (player != null) {
|
||||
message = message.replace("%player%", player.getName());
|
||||
}
|
||||
|
||||
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), message);
|
||||
}
|
||||
@@ -28,10 +27,13 @@ public class BungeeAction implements Action {
|
||||
@Override
|
||||
public void executePlayerCommand(String action, UUID uuid, String command, String message) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (player != null)
|
||||
message = command.replace("%player%", player.getName());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
message = StringUtils.replace(message, "%player%", player.getName());
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
ProxyServer.getInstance().getPluginManager().dispatchCommand(player, message);
|
||||
}
|
||||
@@ -39,19 +41,18 @@ public class BungeeAction implements Action {
|
||||
@Override
|
||||
public void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
title = ResponseHandler.replaceArgsVariables(title, command);
|
||||
subTitle = ResponseHandler.replaceArgsVariables(subTitle, command);
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
title = StringUtils.replace(title, "%player%", player.getName());
|
||||
subTitle = StringUtils.replace(subTitle, "%player%", player.getName());
|
||||
|
||||
Title titleObj = ProxyServer.getInstance().createTitle();
|
||||
titleObj.title(TextComponent.fromLegacyText(StringUtils.replace(title, "&", "§", "%player%", player.getName())));
|
||||
titleObj.subTitle(TextComponent.fromLegacyText(StringUtils.replace(subTitle, "&", "§", "%player%", player.getName())));
|
||||
titleObj.fadeIn(fadeIn);
|
||||
titleObj.stay(stay);
|
||||
titleObj.fadeOut(fadeOut);
|
||||
player.sendTitle(titleObj);
|
||||
MessageTranslator.sendTitle(player, title, subTitle, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,16 +61,32 @@ public class BungeeAction implements Action {
|
||||
|
||||
@Override
|
||||
public void playSound(String action, UUID uuid, String soundName, float volume, float pitch) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
MessageTranslator.playSound(player, soundName, volume, pitch);
|
||||
} catch (Exception exception) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > The sound \"" + soundName + "\" could not be found!");
|
||||
Logger.warning(" > Here's an example of an existing sound effect:");
|
||||
Logger.warning(" > entity.ender_dragon.growl");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionbar(String action, UUID uuid, String command, String message) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (player == null)
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(StringUtils.replace(message, "%player%", player.getName())));
|
||||
message = StringUtils.replace(message, "%player%", player.getName());
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
MessageTranslator.sendActionbar(player, message);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,11 @@ package de.rayzs.pat.utils.response.action.impl;
|
||||
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.message.replacer.PlaceholderReplacer;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import de.rayzs.pat.utils.response.action.Action;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
@@ -22,11 +20,13 @@ public class ModernBukkitAction implements Action {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (player != null)
|
||||
message = message.replace("%player%", player.getName());
|
||||
if (player != null) {
|
||||
message = StringUtils.replace(message, "%player%", player.getName());
|
||||
}
|
||||
|
||||
if (message.contains("%"))
|
||||
if (message.contains("%")) {
|
||||
message = PlaceholderReplacer.replace(player, message);
|
||||
}
|
||||
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), message);
|
||||
}
|
||||
@@ -34,39 +34,45 @@ public class ModernBukkitAction implements Action {
|
||||
@Override
|
||||
public void executePlayerCommand(String action, UUID uuid, String command, String message) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
message = StringUtils.replace(message, "%player%", player.getName());
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if(player != null)
|
||||
message = message.replace("%player%", player.getName());
|
||||
|
||||
if (message.contains("%"))
|
||||
if (message.contains("%")) {
|
||||
message = PlaceholderReplacer.replace(player, message);
|
||||
}
|
||||
|
||||
if (player != null)
|
||||
Bukkit.dispatchCommand(player, message);
|
||||
Bukkit.dispatchCommand(player, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
title = ResponseHandler.replaceArgsVariables(title, command);
|
||||
subTitle = ResponseHandler.replaceArgsVariables(subTitle, command);
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
title = StringUtils.replace(title, "&", "§", "%player%", player.getName());
|
||||
subTitle = StringUtils.replace(subTitle, "&", "§", "%player%", player.getName());
|
||||
|
||||
title = PlaceholderReplacer.replace(player, StringUtils.replace(title, "&", "§", "%player%", player.getName()));
|
||||
subTitle = PlaceholderReplacer.replace(player, StringUtils.replace(subTitle, "&", "§", "%player%", player.getName()));
|
||||
|
||||
player.sendTitle(title, subTitle, fadeIn, stay, fadeOut);
|
||||
MessageTranslator.sendTitle(player, title, subTitle, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPotionEffect(String action, UUID uuid, String potionEffectTypeName, int duration, int amplifier) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null)
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PotionEffectType potionEffectType = null;
|
||||
try {
|
||||
@@ -88,12 +94,12 @@ public class ModernBukkitAction implements Action {
|
||||
public void playSound(String action, UUID uuid, String soundName, float volume, float pitch) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null)
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Sound sound = Sound.valueOf(soundName);
|
||||
player.playSound(player.getLocation(), sound, volume, pitch);
|
||||
MessageTranslator.playSound(player, soundName, volume, pitch);
|
||||
} catch (Exception exception) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > The sound \"" + soundName + "\" could not be found!");
|
||||
@@ -105,13 +111,14 @@ public class ModernBukkitAction implements Action {
|
||||
@Override
|
||||
public void sendActionbar(String action, UUID uuid, String command, String message) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
message = StringUtils.replace(message, "%player%", player.getName());
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
message = PlaceholderReplacer.replace(player, StringUtils.replace(message, "&", "§", "%player%", player.getName()));
|
||||
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
|
||||
MessageTranslator.sendActionbar(player, message);
|
||||
}
|
||||
}
|
||||
@@ -26,11 +26,13 @@ public class OldBukkitAction implements Action {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if(player != null)
|
||||
message = message.replace("%player%", player.getName());
|
||||
if(player != null) {
|
||||
message = StringUtils.replace(message, "%player%", player.getName());
|
||||
}
|
||||
|
||||
if (message.contains("%"))
|
||||
if (message.contains("%")) {
|
||||
message = PlaceholderReplacer.replace(player, message);
|
||||
}
|
||||
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), message);
|
||||
}
|
||||
@@ -38,28 +40,37 @@ public class OldBukkitAction implements Action {
|
||||
@Override
|
||||
public void executePlayerCommand(String action, UUID uuid, String command, String message) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
message = StringUtils.replace(message, "%player%", player.getName());
|
||||
|
||||
if (player != null)
|
||||
message = message.replace("%player%", player.getName());
|
||||
|
||||
if (message.contains("%"))
|
||||
if (message.contains("%")) {
|
||||
message = PlaceholderReplacer.replace(player, message);
|
||||
}
|
||||
|
||||
if (player != null)
|
||||
Bukkit.dispatchCommand(player, message);
|
||||
Bukkit.dispatchCommand(player, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
title = StringUtils.replace(title, "&", "§", "%player%", player.getName());
|
||||
subTitle = StringUtils.replace(title, "&", "§", "%player%", player.getName());
|
||||
|
||||
title = ResponseHandler.replaceArgsVariables(title, command);
|
||||
subTitle = ResponseHandler.replaceArgsVariables(subTitle, command);
|
||||
|
||||
if (player == null) return;
|
||||
|
||||
title = PlaceholderReplacer.replace(player, StringUtils.replace(title, "&", "§", "%player%", player.getName()));
|
||||
subTitle = PlaceholderReplacer.replace(player, StringUtils.replace(subTitle, "&", "§", "%player%", player.getName()));
|
||||
title = PlaceholderReplacer.replace(player, title);
|
||||
subTitle = PlaceholderReplacer.replace(player, subTitle);
|
||||
|
||||
player.sendTitle(title, subTitle);
|
||||
}
|
||||
@@ -68,8 +79,9 @@ public class OldBukkitAction implements Action {
|
||||
public void addPotionEffect(String action, UUID uuid, String potionEffectTypeName, int duration, int amplifier) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null)
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PotionEffectType potionEffectType = null;
|
||||
try {
|
||||
@@ -91,8 +103,9 @@ public class OldBukkitAction implements Action {
|
||||
public void playSound(String action, UUID uuid, String soundName, float volume, float pitch) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if(player == null)
|
||||
if(player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Sound sound = Sound.valueOf(soundName);
|
||||
@@ -108,16 +121,19 @@ public class OldBukkitAction implements Action {
|
||||
@Override
|
||||
public void sendActionbar(String action, UUID uuid, String command, String message) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (player == null)
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
message = PlaceholderReplacer.replace(player, StringUtils.replace(message, "&", "§", "%player%", player.getName()));
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
message = StringUtils.replace(message, "&", "§", "%player%", player.getName());
|
||||
message = PlaceholderReplacer.replace(player, message);
|
||||
|
||||
try {
|
||||
if (versionPackage == null)
|
||||
if (versionPackage == null) {
|
||||
versionPackage = Reflection.getVersionPackageName();
|
||||
}
|
||||
|
||||
Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player);
|
||||
Constructor<?> constructor = (Objects.<Class<?>>requireNonNull(Class.forName("net.minecraft.server." + versionPackage + ".PacketPlayOutChat"))).getConstructor(Class.forName("net.minecraft.server." + versionPackage + ".IChatBaseComponent"), byte.class);
|
||||
|
||||
@@ -3,14 +3,12 @@ package de.rayzs.pat.utils.response.action.impl;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import de.rayzs.pat.utils.response.action.Action;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.time.*;
|
||||
|
||||
public class VelocityAction implements Action {
|
||||
|
||||
@@ -19,8 +17,9 @@ public class VelocityAction implements Action {
|
||||
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (optPlayer.isPresent())
|
||||
if (optPlayer.isPresent()) {
|
||||
message = message.replace("%player%", optPlayer.get().getUsername());
|
||||
}
|
||||
|
||||
VelocityLoader.getServer().getCommandManager().executeAsync(VelocityLoader.getServer().getConsoleCommandSource(), message);
|
||||
}
|
||||
@@ -28,30 +27,36 @@ public class VelocityAction implements Action {
|
||||
@Override
|
||||
public void executePlayerCommand(String action, UUID uuid, String command, String message) {
|
||||
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
|
||||
|
||||
if (optPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = optPlayer.get();
|
||||
|
||||
message = message.replace("%player%", player.getUsername());
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (optPlayer.isPresent())
|
||||
message = command.replace("%player%", optPlayer.get().getUsername());
|
||||
|
||||
VelocityLoader.getServer().getCommandManager().executeAsync(optPlayer.get(), message);
|
||||
VelocityLoader.getServer().getCommandManager().executeAsync(player, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
|
||||
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
|
||||
|
||||
if (optPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = optPlayer.get();
|
||||
|
||||
title = ResponseHandler.replaceArgsVariables(title, command);
|
||||
subTitle = ResponseHandler.replaceArgsVariables(subTitle, command);
|
||||
|
||||
if (!optPlayer.isPresent()) return;
|
||||
title = StringUtils.replace(title, "%player%", player.getUsername());
|
||||
subTitle = StringUtils.replace(subTitle, "%player%", player.getUsername());
|
||||
|
||||
Player player = optPlayer.get();
|
||||
Title titleObj = Title.title(
|
||||
MiniMessage.miniMessage().deserialize(MessageTranslator.replaceMessage(StringUtils.replace(title, "%player%", player.getUsername()))),
|
||||
MiniMessage.miniMessage().deserialize(MessageTranslator.replaceMessage(StringUtils.replace(subTitle, "%player%", player.getUsername()))),
|
||||
Title.Times.times(Duration.ofMillis(fadeIn), Duration.ofMillis(stay), Duration.ofMillis(fadeOut))
|
||||
);
|
||||
|
||||
player.showTitle(titleObj);
|
||||
MessageTranslator.sendTitle(player, title, subTitle, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,17 +65,37 @@ public class VelocityAction implements Action {
|
||||
|
||||
@Override
|
||||
public void playSound(String action, UUID uuid, String soundName, float volume, float pitch) {
|
||||
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
|
||||
|
||||
if (optPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = optPlayer.get();
|
||||
|
||||
try {
|
||||
MessageTranslator.playSound(player, soundName, volume, pitch);
|
||||
} catch (Exception exception) {
|
||||
Logger.warning("! Failed to read action: " + action);
|
||||
Logger.warning(" > The sound \"" + soundName + "\" could not be found!");
|
||||
Logger.warning(" > Here's an example of an existing sound effect:");
|
||||
Logger.warning(" > entity.ender_dragon.growl");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionbar(String action, UUID uuid, String command, String message) {
|
||||
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
|
||||
if (!optPlayer.isPresent())
|
||||
if (optPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = optPlayer.get();
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize(MessageTranslator.replaceMessage(StringUtils.replace(message, "%player%", player.getUsername()))));
|
||||
|
||||
message = ResponseHandler.replaceArgsVariables(message, command);
|
||||
message = StringUtils.replace(message, "%player%", player.getUsername());
|
||||
|
||||
MessageTranslator.sendActionbar(player, message);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,16 @@ package de.rayzs.pat.utils.scheduler;
|
||||
|
||||
import de.rayzs.pat.utils.scheduler.impl.*;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PATScheduler {
|
||||
|
||||
public static void execute(Runnable runnable, Player player) {
|
||||
if (Reflection.isFoliaServer())
|
||||
new FoliaScheduler().getInstance(runnable, player);
|
||||
else createScheduler(runnable);
|
||||
}
|
||||
|
||||
public static PATSchedulerTask createScheduler(Runnable runnable, long time, long period) {
|
||||
return Reflection.isFoliaServer()
|
||||
? new FoliaScheduler().getInstance(false, runnable, time, period)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.rayzs.pat.utils.scheduler;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface PATSchedulerTask {
|
||||
|
||||
PATSchedulerTask getInstance(boolean async, Runnable runnable, long time, long period);
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.rayzs.pat.utils.scheduler.impl;
|
||||
import de.rayzs.pat.utils.scheduler.PATSchedulerTask;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BukkitScheduler implements PATSchedulerTask {
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import de.rayzs.pat.utils.scheduler.PATSchedulerTask;
|
||||
import io.papermc.paper.threadedregions.scheduler.*;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FoliaScheduler implements PATSchedulerTask {
|
||||
|
||||
@@ -11,6 +12,15 @@ public class FoliaScheduler implements PATSchedulerTask {
|
||||
|
||||
private ScheduledTask task;
|
||||
|
||||
public void getInstance(Runnable runnable, Player player) {
|
||||
|
||||
if (player == null) {
|
||||
SCHEDULER.execute(BukkitLoader.getPlugin(), runnable);
|
||||
} else {
|
||||
player.getScheduler().run(BukkitLoader.getPlugin(), scheduledTask -> runnable.run(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PATSchedulerTask getInstance(boolean async, Runnable runnable, long time, long period) {
|
||||
this.task = SCHEDULER.runAtFixedRate(BukkitLoader.getPlugin(), __ -> runnable.run(), time, period);
|
||||
|
||||
Loaded 100 of 114 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user