mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-05-03 11:40:29 +00:00
Compare commits
103 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
c97de82970
|
|||
|
f58a212782
|
|||
|
42e8a861a3
|
|||
|
c6a45e6b0c
|
|||
|
81491398e9
|
|||
|
9cb81330e9
|
|||
|
f1b744bfbe
|
|||
|
b855764e19
|
|||
|
5e4b151d44
|
|||
| 4221ebb892 | |||
|
d93076eb81
|
|||
|
1d2c11c538
|
|||
|
e495b11587
|
|||
|
b250776c82
|
|||
|
13cfe8db13
|
|||
|
d30c70c8c4
|
|||
|
3aa76384c3
|
|||
|
92c965bfc6
|
|||
|
1fb429ea77
|
|||
|
338297192c
|
|||
|
1d3bd7e101
|
|||
|
96c0dff8c1
|
|||
|
|
23aeb81308 | ||
|
|
c84b987b9e | ||
|
8177260991
|
|||
|
287f037774
|
|||
|
c633f1a106
|
|||
|
9fd1da5f92
|
|||
|
0050575aff
|
|||
|
6eab4ef602
|
|||
|
12acc16376
|
|||
|
8b9af8838d
|
|||
|
|
81bf06e2df
|
||
|
41b1dab8cc
|
|||
|
a437db32b8
|
|||
|
2bd79f628e
|
|||
|
93c1cd8e4c
|
|||
|
f27d54beb8
|
|||
|
91ea0b08dc
|
|||
|
199c1c7135
|
|||
|
dab5f26e2c
|
|||
|
c622bc7b63
|
|||
|
881691a92d
|
|||
| 079606c9da | |||
|
ea54a0bc49
|
|||
|
69e91c3e42
|
|||
|
|
d8704c8a8f
|
||
|
|
981d42d4a8
|
||
|
e0bca62cdb
|
|||
|
|
9ebfafbeef | ||
|
70eebdc9ec
|
|||
|
e85e18dad8
|
|||
|
995c9045df
|
|||
|
2485150ddc
|
|||
|
32735466d6
|
|||
|
e8715e5399
|
|||
|
71287055b4
|
|||
|
8b48736bc1
|
|||
|
a2e6aff4c2
|
|||
|
7c1c1183cf
|
|||
|
7f35b64d93
|
|||
|
3dc3d80045
|
|||
|
765e6fe122
|
|||
|
e8514b3e8b
|
|||
|
e1d401639e
|
|||
|
f8c304d441
|
|||
|
e6b789229c
|
|||
|
025b555457
|
|||
|
7029552c02
|
|||
|
62007992a7
|
|||
|
8a6d97e923
|
|||
|
a65b1cdf5c
|
|||
|
25441a5122
|
|||
|
b9c7c31c09
|
|||
|
27358d2f5f
|
|||
|
c736f39e7f
|
|||
| 7b90a34fae | |||
| 1593c2d628 | |||
| 5c4de82714 | |||
| 9e48e472a6 | |||
| b04e13136b | |||
| 8821d3995c | |||
| 9218e6ad42 | |||
| fa6bcf7cb8 | |||
| 830b930394 | |||
| 450b0ee396 | |||
| dd4cc2a5bb | |||
| fd3aa51288 | |||
|
|
99941c733f | ||
| 7fb9c4689e | |||
| 5066a18dd7 | |||
| 265933f36e | |||
|
|
9a583369e8 | ||
|
|
d9e5a21c14 | ||
|
|
4f43c98c87 | ||
| 26b58252eb | |||
|
|
73879640e5 | ||
|
|
c5040c9348 | ||
|
|
9ca72ff921 | ||
| 9050264b4d | |||
|
|
5b5f748cc9 | ||
|
|
47127c8520 | ||
|
|
b857bdb771 |
52
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
52
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
# used https://github.com/PaperMC/Paper/blob/master/.github/ISSUE_TEMPLATE/behavior-bug-or-plugin-incompatibility.yml as template
|
||||||
|
name: Bug or incompatibility
|
||||||
|
description: report issues within RedisBungee
|
||||||
|
labels: [ "waiting" ]
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: intended behavior
|
||||||
|
description: what you expected to happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: what the behavior you actually saw
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Steps to reproduce
|
||||||
|
description: either a video, or way you want to present it.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Velocity or Bungeecord Versions
|
||||||
|
description: |
|
||||||
|
Please provide Proxy version for either Bungeecord or Velocity
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: RedisBungee Version & Redis Version
|
||||||
|
description: |
|
||||||
|
RedisBungee version is Different from Redis Version!
|
||||||
|
good example:
|
||||||
|
|
||||||
|
Redis Version: 7.2
|
||||||
|
RedisBungee Version: 0.12.0
|
||||||
|
|
||||||
|
in-case you used development branch you can use git commit hash Instead of the version
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Other
|
||||||
|
description: |
|
||||||
|
extra information that we might need to know?
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
32
.github/ISSUE_TEMPLATE/bug_report.md
vendored
32
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,32 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: if you find a bug please report it here...
|
|
||||||
title: ''
|
|
||||||
labels: waiting
|
|
||||||
assignees: ham1255
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Screenshots**
|
|
||||||
If applicable, add screenshots to help explain your problem.
|
|
||||||
|
|
||||||
**Redis version? it should be at least 6 and above.**
|
|
||||||
|
|
||||||
**Bungeecord version or (the bungee fork name eg: waterfall) and your plugins**
|
|
||||||
|
|
||||||
|
|
||||||
**console logs?**
|
|
||||||
please provide any errors if there any.
|
|
||||||
10
.github/ISSUE_TEMPLATE/question.md
vendored
10
.github/ISSUE_TEMPLATE/question.md
vendored
@@ -1,10 +0,0 @@
|
|||||||
---
|
|
||||||
name: Question
|
|
||||||
about: ask your questions here
|
|
||||||
title: ''
|
|
||||||
labels: question
|
|
||||||
assignees: GovindasOM, ham1255
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## What is your question?
|
|
||||||
10
.github/ISSUE_TEMPLATE/question.yml
vendored
Normal file
10
.github/ISSUE_TEMPLATE/question.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# used https://github.com/PaperMC/Paper/blob/master/.github/ISSUE_TEMPLATE/behavior-bug-or-plugin-incompatibility.yml as template
|
||||||
|
name: Ask Question
|
||||||
|
description: Ask any questions to the developers
|
||||||
|
labels: [ "question"]
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Your question?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
@@ -5,9 +5,9 @@ name: RedisBungee Build
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ develop ]
|
branches: [ stable, develop ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ develop ]
|
branches: [ stable, develop ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -16,27 +16,27 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 21
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v2
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '21'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
- name: Build with Maven
|
- name: Build with gradle
|
||||||
run: mvn -B package --file pom.xml
|
run: ./gradlew shadowJar
|
||||||
- name: Upload Bungee
|
- name: Upload Bungee
|
||||||
uses: actions/upload-artifact@v2.2.3
|
uses: actions/upload-artifact@v4.4.0
|
||||||
with:
|
with:
|
||||||
# Artifact name
|
# Artifact name
|
||||||
name: RedisBungee-Bungee
|
name: RedisBungee-Bungee
|
||||||
# Destination path
|
# Destination path
|
||||||
path: RedisBungee-Bungee/target/*
|
path: redisbungee/proxies/bungeecord/build/libs/*
|
||||||
- name: Upload Velocity
|
- name: Upload Velocity
|
||||||
uses: actions/upload-artifact@v2.2.3
|
uses: actions/upload-artifact@v4.4.0
|
||||||
with:
|
with:
|
||||||
name: RedisBungee-Velocity
|
name: RedisBungee-Velocity
|
||||||
path: RedisBungee-Velocity/target/*
|
path: redisbungee/proxies/velocity/build/libs/*
|
||||||
- name: Upload API
|
- name: Upload API
|
||||||
uses: actions/upload-artifact@v2.2.3
|
uses: actions/upload-artifact@v4.4.0
|
||||||
with:
|
with:
|
||||||
name: RedisBungee-API
|
name: RedisBungee-API
|
||||||
path: RedisBungee-API/target/*
|
path: redisbungee/api/build/libs/*
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -39,5 +39,12 @@ manifest.mf
|
|||||||
|
|
||||||
*.versionBackup
|
*.versionBackup
|
||||||
*.versionsBackup
|
*.versionsBackup
|
||||||
|
# gradle
|
||||||
|
.gradle
|
||||||
|
|
||||||
# java docs
|
# java docs
|
||||||
javadoc
|
javadoc
|
||||||
|
|
||||||
|
# run-server folders
|
||||||
|
**/run/
|
||||||
|
!src/**/run/
|
||||||
|
|||||||
819
LICENSE
819
LICENSE
@@ -1,203 +1,674 @@
|
|||||||
Eclipse Public License - v 1.0
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
1. DEFINITIONS
|
Preamble
|
||||||
|
|
||||||
"Contribution" means:
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
a) in the case of the initial Contributor, the initial code and documentation
|
The licenses for most software and other practical works are designed
|
||||||
distributed under this Agreement, and
|
to take away your freedom to share and change the works. By contrast,
|
||||||
b) in the case of each subsequent Contributor:
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
i) changes to the Program, and
|
share and change all versions of a program--to make sure it remains free
|
||||||
ii) additions to the Program;
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
where such changes and/or additions to the Program originate from and are
|
When we speak of free software, we are referring to freedom, not
|
||||||
distributed by that particular Contributor. A Contribution 'originates'
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
from a Contributor if it was added to the Program by such Contributor
|
have the freedom to distribute copies of free software (and charge for
|
||||||
itself or anyone acting on such Contributor's behalf. Contributions do not
|
them if you wish), that you receive source code or can get it if you
|
||||||
include additions to the Program which: (i) are separate modules of
|
want it, that you can change the software or use pieces of it in new
|
||||||
software distributed in conjunction with the Program under their own
|
free programs, and that you know you can do these things.
|
||||||
license agreement, and (ii) are not derivative works of the Program.
|
|
||||||
|
|
||||||
"Contributor" means any person or entity that distributes the Program.
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
"Licensed Patents" mean patent claims licensable by a Contributor which are
|
For example, if you distribute copies of such a program, whether
|
||||||
necessarily infringed by the use or sale of its Contribution alone or when
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
combined with the Program.
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
"Program" means the Contributions distributed in accordance with this
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
Agreement.
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
"Recipient" means anyone who receives the Program under this Agreement,
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
including all Contributors.
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
2. GRANT OF RIGHTS
|
Some devices are designed to deny users access to install or run
|
||||||
a) Subject to the terms of this Agreement, each Contributor hereby grants
|
modified versions of the software inside them, although the manufacturer
|
||||||
Recipient a non-exclusive, worldwide, royalty-free copyright license to
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
reproduce, prepare derivative works of, publicly display, publicly
|
protecting users' freedom to change the software. The systematic
|
||||||
perform, distribute and sublicense the Contribution of such Contributor,
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
if any, and such derivative works, in source code and object code form.
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
b) Subject to the terms of this Agreement, each Contributor hereby grants
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
Recipient a non-exclusive, worldwide, royalty-free patent license under
|
products. If such problems arise substantially in other domains, we
|
||||||
Licensed Patents to make, use, sell, offer to sell, import and otherwise
|
stand ready to extend this provision to those domains in future versions
|
||||||
transfer the Contribution of such Contributor, if any, in source code and
|
of the GPL, as needed to protect the freedom of users.
|
||||||
object code form. This patent license shall apply to the combination of
|
|
||||||
the Contribution and the Program if, at the time the Contribution is
|
|
||||||
added by the Contributor, such addition of the Contribution causes such
|
|
||||||
combination to be covered by the Licensed Patents. The patent license
|
|
||||||
shall not apply to any other combinations which include the Contribution.
|
|
||||||
No hardware per se is licensed hereunder.
|
|
||||||
c) Recipient understands that although each Contributor grants the licenses
|
|
||||||
to its Contributions set forth herein, no assurances are provided by any
|
|
||||||
Contributor that the Program does not infringe the patent or other
|
|
||||||
intellectual property rights of any other entity. Each Contributor
|
|
||||||
disclaims any liability to Recipient for claims brought by any other
|
|
||||||
entity based on infringement of intellectual property rights or
|
|
||||||
otherwise. As a condition to exercising the rights and licenses granted
|
|
||||||
hereunder, each Recipient hereby assumes sole responsibility to secure
|
|
||||||
any other intellectual property rights needed, if any. For example, if a
|
|
||||||
third party patent license is required to allow Recipient to distribute
|
|
||||||
the Program, it is Recipient's responsibility to acquire that license
|
|
||||||
before distributing the Program.
|
|
||||||
d) Each Contributor represents that to its knowledge it has sufficient
|
|
||||||
copyright rights in its Contribution, if any, to grant the copyright
|
|
||||||
license set forth in this Agreement.
|
|
||||||
|
|
||||||
3. REQUIREMENTS
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
A Contributor may choose to distribute the Program in object code form under
|
The precise terms and conditions for copying, distribution and
|
||||||
its own license agreement, provided that:
|
modification follow.
|
||||||
|
|
||||||
a) it complies with the terms and conditions of this Agreement; and
|
TERMS AND CONDITIONS
|
||||||
b) its license agreement:
|
|
||||||
i) effectively disclaims on behalf of all Contributors all warranties
|
|
||||||
and conditions, express and implied, including warranties or
|
|
||||||
conditions of title and non-infringement, and implied warranties or
|
|
||||||
conditions of merchantability and fitness for a particular purpose;
|
|
||||||
ii) effectively excludes on behalf of all Contributors all liability for
|
|
||||||
damages, including direct, indirect, special, incidental and
|
|
||||||
consequential damages, such as lost profits;
|
|
||||||
iii) states that any provisions which differ from this Agreement are
|
|
||||||
offered by that Contributor alone and not by any other party; and
|
|
||||||
iv) states that source code for the Program is available from such
|
|
||||||
Contributor, and informs licensees how to obtain it in a reasonable
|
|
||||||
manner on or through a medium customarily used for software exchange.
|
|
||||||
|
|
||||||
When the Program is made available in source code form:
|
0. Definitions.
|
||||||
|
|
||||||
a) it must be made available under this Agreement; and
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
b) a copy of this Agreement must be included with each copy of the Program.
|
|
||||||
Contributors may not remove or alter any copyright notices contained
|
|
||||||
within the Program.
|
|
||||||
|
|
||||||
Each Contributor must identify itself as the originator of its Contribution,
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
if
|
works, such as semiconductor masks.
|
||||||
any, in a manner that reasonably allows subsequent Recipients to identify the
|
|
||||||
originator of the Contribution.
|
|
||||||
|
|
||||||
4. COMMERCIAL DISTRIBUTION
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
Commercial distributors of software may accept certain responsibilities with
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
respect to end users, business partners and the like. While this license is
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
intended to facilitate the commercial use of the Program, the Contributor who
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
includes the Program in a commercial product offering should do so in a manner
|
earlier work or a work "based on" the earlier work.
|
||||||
which does not create potential liability for other Contributors. Therefore,
|
|
||||||
if a Contributor includes the Program in a commercial product offering, such
|
|
||||||
Contributor ("Commercial Contributor") hereby agrees to defend and indemnify
|
|
||||||
every other Contributor ("Indemnified Contributor") against any losses,
|
|
||||||
damages and costs (collectively "Losses") arising from claims, lawsuits and
|
|
||||||
other legal actions brought by a third party against the Indemnified
|
|
||||||
Contributor to the extent caused by the acts or omissions of such Commercial
|
|
||||||
Contributor in connection with its distribution of the Program in a commercial
|
|
||||||
product offering. The obligations in this section do not apply to any claims
|
|
||||||
or Losses relating to any actual or alleged intellectual property
|
|
||||||
infringement. In order to qualify, an Indemnified Contributor must:
|
|
||||||
a) promptly notify the Commercial Contributor in writing of such claim, and
|
|
||||||
b) allow the Commercial Contributor to control, and cooperate with the
|
|
||||||
Commercial Contributor in, the defense and any related settlement
|
|
||||||
negotiations. The Indemnified Contributor may participate in any such claim at
|
|
||||||
its own expense.
|
|
||||||
|
|
||||||
For example, a Contributor might include the Program in a commercial product
|
A "covered work" means either the unmodified Program or a work based
|
||||||
offering, Product X. That Contributor is then a Commercial Contributor. If
|
on the Program.
|
||||||
that Commercial Contributor then makes performance claims, or offers
|
|
||||||
warranties related to Product X, those performance claims and warranties are
|
|
||||||
such Commercial Contributor's responsibility alone. Under this section, the
|
|
||||||
Commercial Contributor would have to defend claims against the other
|
|
||||||
Contributors related to those performance claims and warranties, and if a
|
|
||||||
court requires any other Contributor to pay any damages as a result, the
|
|
||||||
Commercial Contributor must pay those damages.
|
|
||||||
|
|
||||||
5. NO WARRANTY
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN
|
To "convey" a work means any kind of propagation that enables other
|
||||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE,
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each
|
|
||||||
Recipient is solely responsible for determining the appropriateness of using
|
|
||||||
and distributing the Program and assumes all risks associated with its
|
|
||||||
exercise of rights under this Agreement , including but not limited to the
|
|
||||||
risks and costs of program errors, compliance with applicable laws, damage to
|
|
||||||
or loss of data, programs or equipment, and unavailability or interruption of
|
|
||||||
operations.
|
|
||||||
|
|
||||||
6. DISCLAIMER OF LIABILITY
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
|
1. Source Code.
|
||||||
CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
|
|
||||||
LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
|
|
||||||
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
|
|
||||||
OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
7. GENERAL
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
If any provision of this Agreement is invalid or unenforceable under
|
A "Standard Interface" means an interface that either is an official
|
||||||
applicable law, it shall not affect the validity or enforceability of the
|
standard defined by a recognized standards body, or, in the case of
|
||||||
remainder of the terms of this Agreement, and without further action by the
|
interfaces specified for a particular programming language, one that
|
||||||
parties hereto, such provision shall be reformed to the minimum extent
|
is widely used among developers working in that language.
|
||||||
necessary to make such provision valid and enforceable.
|
|
||||||
|
|
||||||
If Recipient institutes patent litigation against any entity (including a
|
The "System Libraries" of an executable work include anything, other
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Program itself
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
(excluding combinations of the Program with other software or hardware)
|
packaging a Major Component, but which is not part of that Major
|
||||||
infringes such Recipient's patent(s), then such Recipient's rights granted
|
Component, and (b) serves only to enable use of the work with that
|
||||||
under Section 2(b) shall terminate as of the date such litigation is filed.
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
All Recipient's rights under this Agreement shall terminate if it fails to
|
The "Corresponding Source" for a work in object code form means all
|
||||||
comply with any of the material terms or conditions of this Agreement and does
|
the source code needed to generate, install, and (for an executable
|
||||||
not cure such failure in a reasonable period of time after becoming aware of
|
work) run the object code and to modify the work, including scripts to
|
||||||
such noncompliance. If all Recipient's rights under this Agreement terminate,
|
control those activities. However, it does not include the work's
|
||||||
Recipient agrees to cease use and distribution of the Program as soon as
|
System Libraries, or general-purpose tools or generally available free
|
||||||
reasonably practicable. However, Recipient's obligations under this Agreement
|
programs which are used unmodified in performing those activities but
|
||||||
and any licenses granted by Recipient relating to the Program shall continue
|
which are not part of the work. For example, Corresponding Source
|
||||||
and survive.
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute copies of this Agreement, but in
|
The Corresponding Source need not include anything that users
|
||||||
order to avoid inconsistency the Agreement is copyrighted and may only be
|
can regenerate automatically from other parts of the Corresponding
|
||||||
modified in the following manner. The Agreement Steward reserves the right to
|
Source.
|
||||||
publish new versions (including revisions) of this Agreement from time to
|
|
||||||
time. No one other than the Agreement Steward has the right to modify this
|
|
||||||
Agreement. The Eclipse Foundation is the initial Agreement Steward. The
|
|
||||||
Eclipse Foundation may assign the responsibility to serve as the Agreement
|
|
||||||
Steward to a suitable separate entity. Each new version of the Agreement will
|
|
||||||
be given a distinguishing version number. The Program (including
|
|
||||||
Contributions) may always be distributed subject to the version of the
|
|
||||||
Agreement under which it was received. In addition, after a new version of the
|
|
||||||
Agreement is published, Contributor may elect to distribute the Program
|
|
||||||
(including its Contributions) under the new version. Except as expressly
|
|
||||||
stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
|
|
||||||
licenses to the intellectual property of any Contributor under this Agreement,
|
|
||||||
whether expressly, by implication, estoppel or otherwise. All rights in the
|
|
||||||
Program not expressly granted under this Agreement are reserved.
|
|
||||||
|
|
||||||
This Agreement is governed by the laws of the State of New York and the
|
The Corresponding Source for a work in source code form is that
|
||||||
intellectual property laws of the United States of America. No party to this
|
same work.
|
||||||
Agreement will bring a legal action under this Agreement more than one year
|
|
||||||
after the cause of action arose. Each party waives its rights to a jury trial in
|
2. Basic Permissions.
|
||||||
any resulting litigation.
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
157
README.md
157
README.md
@@ -1,153 +1,30 @@
|
|||||||
# RedisBungee fork By Limework
|
# ValioBungee: The RedisBungee Limework's rewrite
|
||||||
The original project of RedisBungee is no longer maintained, so we have forked the plugin.
|
|
||||||
|
|
||||||
RedisBungee uses [Redis](https://redis.io) with Java client [Jedis](https://github.com/redis/jedis/)
|
## Why different name?
|
||||||
to Synchronize players data between [BungeeCord](https://github.com/SpigotMC/BungeeCord) or [Velocity*](https://github.com/PaperMC/Velocity) proxies
|
Because from our current understanding we cant use Redis name due trademark restrictions.
|
||||||
|
so we settled with valiobungee. But it doesnt not effect any internals naming schemes like plugin id and so on.
|
||||||
|
|
||||||
Velocity*: *version 3.1.2 or above is only supported, any version below that might work but might be unstable* [#40](https://github.com/ProxioDev/RedisBungee/pull/40)
|
## Downloads
|
||||||
|
|
||||||
## compatibility with original RedisBungee in Bungeecord ecosystem
|
[](https://modrinth.com/plugin/redisbungee)
|
||||||
This fork ensures compatibility with old plugins, so it should work as drop replacement,
|
|
||||||
but since Api has been split from the platform there some changes that have to be done, so your plugin might not work if:
|
|
||||||
|
|
||||||
* there is none at the moment, please report any findings at the issue page.
|
## Wiki
|
||||||
|
|
||||||
Cluster mode compatibility in version 0.8.0:
|
https://github.com/ProxioDev/ValioBungee/wiki
|
||||||
|
|
||||||
If you are using static legacy method `RedisBungee#getPool()` it might fail in:
|
|
||||||
* if Cluster mode is enabled, due fact its Uses different classes
|
|
||||||
* if JedisPool compatibility mode is disabled in the config due fact project internally switched to JedisPooled than Jedis
|
|
||||||
*
|
|
||||||
## License
|
|
||||||
|
|
||||||
This project is distributed under Eclipse Public License 1.0
|
|
||||||
|
|
||||||
You can find it [here](https://github.com/proxiodev/RedisBungee/blob/master/LICENSE)
|
|
||||||
|
|
||||||
You can find the original RedisBungee is by [astei](https://github.com/astei) and project can be found [here](https://github.com/minecrafter/RedisBungee) or spigot page [here, but its no longer available](https://www.spigotmc.org/resources/redisbungee.13494/)
|
|
||||||
|
|
||||||
## notes
|
|
||||||
If you are looking to use Original RedisBungee without a change to internals,
|
|
||||||
with critical bugs fixed, please use version [0.6.5](https://github.com/ProxioDev/RedisBungee/releases/tag/0.6.5) and java docs For legacy Version [0.6.5](https://proxiodev.github.io/RedisBungee-JavaDocs/0.6.5-SNAPSHOT/)
|
|
||||||
as its last version before internal changes. please note that you will not get support for any old builds unless critical bugs effecting both 0.6.5 and 0.7.0 or above.
|
|
||||||
|
|
||||||
*if you are here for transferring players to another proxy when the first proxy crashes or whatever this plugin won't do it, tell mojang to implement transfer packet*
|
|
||||||
[Click here, for more information about transfer packet](https://hypixel.net/threads/why-do-we-need-transfer-packets.1390307/)
|
|
||||||
|
|
||||||
SpigotMC resource page: [click](https://www.spigotmc.org/resources/redisbungee.87700/)
|
|
||||||
## Supported Redis versions
|
|
||||||
| Redis version | Supported |
|
|
||||||
|:-------------:|:---------:|
|
|
||||||
| 1.x.x | ✖ |
|
|
||||||
| 2.x.x | ✖ |
|
|
||||||
| 3.x.x | ✔ |
|
|
||||||
| 4.x.x | ✔ |
|
|
||||||
| 5.x.x | ✔ |
|
|
||||||
| 6.x.x | ✔ |
|
|
||||||
| 7.x.x | ✔ |
|
|
||||||
|
|
||||||
|
|
||||||
## Implementing RedisBungee in your plugin: [](https://github.com/Limework/RedisBungee/actions/workflows/maven.yml) [](https://jitpack.io/#ProxioDev/redisbungee)
|
|
||||||
|
|
||||||
RedisBungee is distributed as a [maven](https://maven.apache.org) project.
|
|
||||||
|
|
||||||
By using jitpack [](https://jitpack.io/#ProxioDev/redisbungee)
|
|
||||||
|
|
||||||
## Setup jitpack repository
|
|
||||||
```xml
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>jitpack.io</id>
|
|
||||||
<url>https://jitpack.io</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
```
|
|
||||||
## [BungeeCord](https://github.com/SpigotMC/BungeeCord)
|
|
||||||
add this in your project dependencies
|
|
||||||
```xml
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.proxiodev.redisbungee</groupId>
|
|
||||||
<artifactId>RedisBungee-Bungee</artifactId>
|
|
||||||
<version>VERSION</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
```
|
|
||||||
then in your project plugin.yml add `RedisBungee` to `depends` like this
|
|
||||||
```yaml
|
|
||||||
name: "yourplugin"
|
|
||||||
main: your.main.class
|
|
||||||
version: 1.0.0-SNAPSHOT
|
|
||||||
author: idk
|
|
||||||
depends: [ RedisBungee ]
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## [Velocity](https://github.com/PaperMC/Velocity)
|
|
||||||
```xml
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.proxiodev.redisbungee</groupId>
|
|
||||||
<artifactId>RedisBungee-Velocity</artifactId>
|
|
||||||
<version>VERSION</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
```
|
|
||||||
then to make your plugin depends on RedisBungee, make sure your plugin class Annotation have `@Dependency(id = "redisbungee")` like this
|
|
||||||
```java
|
|
||||||
@Plugin(
|
|
||||||
id = "myplugin",
|
|
||||||
name = "My Plugin",
|
|
||||||
version = "0.1.0-beta",
|
|
||||||
dependencies = {
|
|
||||||
@Dependency(id = "redisbungee")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
public class PluginMainClass {
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Getting the latest commits to your code
|
|
||||||
If you want to use the latest commits without waiting for releases.
|
|
||||||
first, install it to your maven local repo
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/ProxioDev/RedisBungee.git
|
|
||||||
cd RedisBungee
|
|
||||||
mvn clean install
|
|
||||||
```
|
|
||||||
then use any of these in your project.
|
|
||||||
```xml
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<artifactId>RedisBungee-Bungee</artifactId>
|
|
||||||
<version>VERSION</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
```
|
|
||||||
```xml
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<artifactId>RedisBungee-Velocity</artifactId>
|
|
||||||
<version>VERSION</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
```
|
|
||||||
## Javadocs
|
|
||||||
|
|
||||||
For current version [0.8.0](https://proxiodev.github.io/RedisBungee-JavaDocs/0.8.0-SNAPSHOT/)
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
**REDISBUNGEE REQUIRES A REDIS SERVER**, preferably with reasonably low latency. The default [config](https://github.com/ProxioDev/RedisBungee/blob/develop/RedisBungee-API/src/main/resources/config.yml) is saved when the plugin first starts.
|
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
You can join our matrix room [here](https://matrix.to/#/!zhedzmRNSZXfuOPZUB:govindas.net?via=govindas.net&via=matrix.org)
|
open an issue with question button
|
||||||
|
|
||||||

|
## License
|
||||||
|
|
||||||
|
This project is distributed under GPLv3
|
||||||
|
|
||||||
## YourKit
|
With API exception as Apache License v2
|
||||||
|
|
||||||
YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of [YourKit Java Profiler](https://www.yourkit.com/java/profiler/), [YourKit .NET Profiler](https://www.yourkit.com/.net/profiler/) and [YourKit YouMonitor](https://www.yourkit.com/youmonitor/).
|
With Original RedisBungee compatiblity layer as EPLv1
|
||||||
|
|
||||||
|
You can find the original RedisBungee is by [astei](https://github.com/astei) and project can be
|
||||||
|
found [here](https://github.com/minecrafter/RedisBungee) or spigot
|
||||||
|
page [here, but its no longer available](https://www.spigotmc.org/resources/redisbungee.13494/)
|
||||||
|
|
||||||

|
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>RedisBungee</artifactId>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<version>0.10.2-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>RedisBungee-API</artifactId>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
<version>3.2.1</version>
|
|
||||||
<configuration>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>bundle-sources</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar-no-fork</goal>
|
|
||||||
<goal>test-jar-no-fork</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<version>3.3.2</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-javadocs</id>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
<destDir>../javadoc/${project.name}</destDir>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
<version>31.1-jre</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>redis.clients</groupId>
|
|
||||||
<artifactId>jedis</artifactId>
|
|
||||||
<version>4.3.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-pool2</artifactId>
|
|
||||||
<version>2.11.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.squareup.okhttp</groupId>
|
|
||||||
<artifactId>okhttp</artifactId>
|
|
||||||
<version>2.7.5</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.13.2</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>configurate-yaml</artifactId>
|
|
||||||
<version>3.7.2</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,471 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisCluster;
|
|
||||||
import redis.clients.jedis.JedisPool;
|
|
||||||
import redis.clients.jedis.JedisPooled;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This abstract class is extended by platform plugin to provide some platform specific methods.
|
|
||||||
* overall its general contains all methods needed by external usage.
|
|
||||||
*
|
|
||||||
* @author Ham1255
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public abstract class AbstractRedisBungeeAPI {
|
|
||||||
protected final RedisBungeePlugin<?> plugin;
|
|
||||||
private static AbstractRedisBungeeAPI abstractRedisBungeeAPI;
|
|
||||||
protected final List<String> reservedChannels;
|
|
||||||
|
|
||||||
AbstractRedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
|
||||||
// this does make sure that no one can place first initiated API class.
|
|
||||||
if (abstractRedisBungeeAPI == null) {
|
|
||||||
abstractRedisBungeeAPI = this;
|
|
||||||
}
|
|
||||||
this.reservedChannels = ImmutableList.of(
|
|
||||||
"redisbungee-allservers",
|
|
||||||
"redisbungee-" + plugin.getConfiguration().getProxyId(),
|
|
||||||
"redisbungee-data"
|
|
||||||
);
|
|
||||||
|
|
||||||
this.plugin = plugin;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a combined count of all players on this network.
|
|
||||||
*
|
|
||||||
* @return a count of all players found
|
|
||||||
*/
|
|
||||||
public final int getPlayerCount() {
|
|
||||||
return plugin.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the last time a player was on. If the player is currently online, this will return 0. If the player has not been recorded,
|
|
||||||
* this will return -1. Otherwise it will return a value in milliseconds.
|
|
||||||
*
|
|
||||||
* @param player a player name
|
|
||||||
* @return the last time a player was on, if online returns a 0
|
|
||||||
*/
|
|
||||||
public final long getLastOnline(@NonNull UUID player) {
|
|
||||||
return plugin.getDataManager().getLastOnline(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the server where the specified player is playing. This function also deals with the case of local players
|
|
||||||
* as well, and will return local information on them.
|
|
||||||
*
|
|
||||||
* @param player a player uuid
|
|
||||||
* @return a String name for the server the player is on. Can be Null if plugins is doing weird stuff to the proxy internals
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public final String getServerNameFor(@NonNull UUID player) {
|
|
||||||
return plugin.getDataManager().getServer(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a combined list of players on this network.
|
|
||||||
* <p>
|
|
||||||
* <strong>Note that this function returns an instance of {@link com.google.common.collect.ImmutableSet}.</strong>
|
|
||||||
*
|
|
||||||
* @return a Set with all players found
|
|
||||||
*/
|
|
||||||
public final Set<UUID> getPlayersOnline() {
|
|
||||||
return plugin.getPlayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a combined list of players on this network, as a collection of usernames.
|
|
||||||
*
|
|
||||||
* @return a Set with all players found
|
|
||||||
* @see #getNameFromUuid(java.util.UUID)
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
public final Collection<String> getHumanPlayersOnline() {
|
|
||||||
Set<String> names = new HashSet<>();
|
|
||||||
for (UUID uuid : getPlayersOnline()) {
|
|
||||||
names.add(getNameFromUuid(uuid, false));
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a full list of players on all servers.
|
|
||||||
*
|
|
||||||
* @return a immutable Multimap with all players found on this server
|
|
||||||
* @since 0.2.5
|
|
||||||
*/
|
|
||||||
public final Multimap<String, UUID> getServerToPlayers() {
|
|
||||||
return plugin.serverToPlayersCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of players on the server with the given name.
|
|
||||||
*
|
|
||||||
* @param server a server name
|
|
||||||
* @return a Set with all players found on this server
|
|
||||||
*/
|
|
||||||
public final Set<UUID> getPlayersOnServer(@NonNull String server) {
|
|
||||||
return ImmutableSet.copyOf(getServerToPlayers().get(server));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of players on the specified proxy.
|
|
||||||
*
|
|
||||||
* @param server a server name
|
|
||||||
* @return a Set with all UUIDs found on this proxy
|
|
||||||
*/
|
|
||||||
public final Set<UUID> getPlayersOnProxy(@NonNull String server) {
|
|
||||||
return plugin.getPlayersOnProxy(server);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience method: Checks if the specified player is online.
|
|
||||||
*
|
|
||||||
* @param player a player name
|
|
||||||
* @return if the player is online
|
|
||||||
*/
|
|
||||||
public final boolean isPlayerOnline(@NonNull UUID player) {
|
|
||||||
return getLastOnline(player) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the {@link java.net.InetAddress} associated with this player.
|
|
||||||
*
|
|
||||||
* @param player the player to fetch the IP for
|
|
||||||
* @return an {@link java.net.InetAddress} if the player is online, null otherwise
|
|
||||||
* @since 0.2.4
|
|
||||||
*/
|
|
||||||
public final InetAddress getPlayerIp(@NonNull UUID player) {
|
|
||||||
return plugin.getDataManager().getIp(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the RedisBungee proxy ID this player is connected to.
|
|
||||||
*
|
|
||||||
* @param player the player to fetch the IP for
|
|
||||||
* @return the proxy the player is connected to, or null if they are offline
|
|
||||||
* @since 0.3.3
|
|
||||||
*/
|
|
||||||
public final String getProxy(@NonNull UUID player) {
|
|
||||||
return plugin.getDataManager().getProxy(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a proxy command to all proxies.
|
|
||||||
*
|
|
||||||
* @param command the command to send and execute
|
|
||||||
* @see #sendProxyCommand(String, String)
|
|
||||||
* @since 0.2.5
|
|
||||||
*/
|
|
||||||
public final void sendProxyCommand(@NonNull String command) {
|
|
||||||
plugin.sendProxyCommand("allservers", command);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a proxy command to the proxy with the given ID. "allservers" means all proxies.
|
|
||||||
*
|
|
||||||
* @param proxyId a proxy ID
|
|
||||||
* @param command the command to send and execute
|
|
||||||
* @see #getProxyId()
|
|
||||||
* @see #getAllProxies()
|
|
||||||
* @since 0.2.5
|
|
||||||
*/
|
|
||||||
public final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
|
|
||||||
plugin.sendProxyCommand(proxyId, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a message to a PubSub channel. The channel has to be subscribed to on this, or another redisbungee instance for
|
|
||||||
* PubSubMessageEvent to fire.
|
|
||||||
*
|
|
||||||
* @param channel The PubSub channel
|
|
||||||
* @param message the message body to send
|
|
||||||
* @since 0.3.3
|
|
||||||
*/
|
|
||||||
public final void sendChannelMessage(@NonNull String channel, @NonNull String message) {
|
|
||||||
plugin.sendChannelMessage(channel, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current BungeeCord / Velocity proxy ID for this server.
|
|
||||||
*
|
|
||||||
* @return the current server ID
|
|
||||||
* @see #getAllProxies()
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
public final String getProxyId() {
|
|
||||||
return plugin.getConfiguration().getProxyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current BungeeCord / Velocity proxy ID for this server.
|
|
||||||
*
|
|
||||||
* @return the current server ID
|
|
||||||
* @see #getAllServers()
|
|
||||||
* @since 0.2.5
|
|
||||||
* @deprecated to avoid confusion between A server and A proxy see #getProxyId()
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public final String getServerId() {
|
|
||||||
return getProxyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all the linked proxies in this network.
|
|
||||||
*
|
|
||||||
* @return the list of all proxies
|
|
||||||
* @see #getProxyId()
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
public final List<String> getAllProxies() {
|
|
||||||
return plugin.getProxiesIds();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all the linked proxies in this network.
|
|
||||||
*
|
|
||||||
* @return the list of all proxies
|
|
||||||
* @see #getServerId()
|
|
||||||
* @since 0.2.5
|
|
||||||
* @deprecated to avoid confusion between A server and A proxy see see {@link #getAllProxies()}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public final List<String> getAllServers() {
|
|
||||||
return getAllProxies();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register (a) PubSub channel(s), so that you may handle PubSubMessageEvent for it.
|
|
||||||
*
|
|
||||||
* @param channels the channels to register
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
public final void registerPubSubChannels(String... channels) {
|
|
||||||
plugin.getPubSubListener().addChannel(channels);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregister (a) PubSub channel(s).
|
|
||||||
*
|
|
||||||
* @param channels the channels to unregister
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
public final void unregisterPubSubChannels(String... channels) {
|
|
||||||
for (String channel : channels) {
|
|
||||||
Preconditions.checkArgument(!reservedChannels.contains(channel), "attempting to unregister internal channel");
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getPubSubListener().removeChannel(channels);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a name from the specified UUID. UUIDs are cached locally and in Redis. This function falls back to Mojang
|
|
||||||
* as a last resort, so calls <strong>may</strong> be blocking.
|
|
||||||
* <p>
|
|
||||||
* For the common use case of translating a list of UUIDs into names, use {@link #getHumanPlayersOnline()} instead.
|
|
||||||
* <p>
|
|
||||||
* If performance is a concern, use {@link #getNameFromUuid(java.util.UUID, boolean)} as this allows you to disable Mojang lookups.
|
|
||||||
*
|
|
||||||
* @param uuid the UUID to fetch the name for
|
|
||||||
* @return the name for the UUID
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
public final String getNameFromUuid(@NonNull UUID uuid) {
|
|
||||||
return getNameFromUuid(uuid, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a name from the specified UUID. UUIDs are cached locally and in Redis. This function can fall back to Mojang
|
|
||||||
* as a last resort if {@code expensiveLookups} is true, so calls <strong>may</strong> be blocking.
|
|
||||||
* <p>
|
|
||||||
* For the common use case of translating the list of online players into names, use {@link #getHumanPlayersOnline()}.
|
|
||||||
* <p>
|
|
||||||
* If performance is a concern, set {@code expensiveLookups} to false as this will disable lookups via Mojang.
|
|
||||||
*
|
|
||||||
* @param uuid the UUID to fetch the name for
|
|
||||||
* @param expensiveLookups whether or not to perform potentially expensive lookups
|
|
||||||
* @return the name for the UUID
|
|
||||||
* @since 0.3.2
|
|
||||||
*/
|
|
||||||
public final String getNameFromUuid(@NonNull UUID uuid, boolean expensiveLookups) {
|
|
||||||
return plugin.getUuidTranslator().getNameFromUuid(uuid, expensiveLookups);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a UUID from the specified name. Names are cached locally and in Redis. This function falls back to Mojang
|
|
||||||
* as a last resort, so calls <strong>may</strong> be blocking.
|
|
||||||
* <p>
|
|
||||||
* If performance is a concern, see {@link #getUuidFromName(String, boolean)}, which disables the following functions:
|
|
||||||
* <ul>
|
|
||||||
* <li>Searching local entries case-insensitively</li>
|
|
||||||
* <li>Searching Mojang</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param name the UUID to fetch the name for
|
|
||||||
* @return the UUID for the name
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
public final UUID getUuidFromName(@NonNull String name) {
|
|
||||||
return getUuidFromName(name, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a UUID from the specified name. Names are cached locally and in Redis. This function falls back to Mojang
|
|
||||||
* as a last resort if {@code expensiveLookups} is true, so calls <strong>may</strong> be blocking.
|
|
||||||
* <p>
|
|
||||||
* If performance is a concern, set {@code expensiveLookups} to false to disable searching Mojang and searching for usernames
|
|
||||||
* case-insensitively.
|
|
||||||
*
|
|
||||||
* @param name the UUID to fetch the name for
|
|
||||||
* @param expensiveLookups whether or not to perform potentially expensive lookups
|
|
||||||
* @return the {@link UUID} for the name
|
|
||||||
* @since 0.3.2
|
|
||||||
*/
|
|
||||||
public final UUID getUuidFromName(@NonNull String name, boolean expensiveLookups) {
|
|
||||||
return plugin.getUuidTranslator().getTranslatedUuid(name, expensiveLookups);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Kicks a player from the network
|
|
||||||
*
|
|
||||||
* @param playerName player name
|
|
||||||
* @param message kick message that player will see on kick
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void kickPlayer(String playerName, String message) {
|
|
||||||
plugin.kickPlayer(playerName, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Kicks a player from the network
|
|
||||||
*
|
|
||||||
* @param playerUUID player name
|
|
||||||
* @param message kick message that player will see on kick
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
public void kickPlayer(UUID playerUUID, String message) {
|
|
||||||
plugin.kickPlayer(playerUUID, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This gives you instance of Jedis
|
|
||||||
*
|
|
||||||
* @return {@link Jedis}
|
|
||||||
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE}
|
|
||||||
* @see #getJedisPool()
|
|
||||||
* @since 0.7.0
|
|
||||||
*/
|
|
||||||
public Jedis requestJedis() {
|
|
||||||
if (getMode() == RedisBungeeMode.SINGLE) {
|
|
||||||
return getJedisPool().getResource();
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Mode is not " + RedisBungeeMode.SINGLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This gets Redis Bungee {@link JedisPool}
|
|
||||||
*
|
|
||||||
* @return {@link JedisPool}
|
|
||||||
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE}
|
|
||||||
* @throws IllegalStateException if JedisPool compatibility mode is disabled in the config
|
|
||||||
* @since 0.6.5
|
|
||||||
*/
|
|
||||||
public JedisPool getJedisPool() {
|
|
||||||
if (getMode() == RedisBungeeMode.SINGLE) {
|
|
||||||
JedisPool jedisPool = ((JedisPooledSummoner) this.plugin.getSummoner()).getCompatibilityJedisPool();
|
|
||||||
if (jedisPool == null) {
|
|
||||||
throw new IllegalStateException("JedisPool compatibility mode is disabled");
|
|
||||||
}
|
|
||||||
return jedisPool;
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Mode is not " + RedisBungeeMode.SINGLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This gives you an instance of JedisCluster that can't be closed
|
|
||||||
* see {@link com.imaginarycode.minecraft.redisbungee.api.summoners.NotClosableJedisCluster}
|
|
||||||
*
|
|
||||||
* @return {@link redis.clients.jedis.JedisCluster}
|
|
||||||
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#CLUSTER}
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
public JedisCluster requestClusterJedis() {
|
|
||||||
if (getMode() == RedisBungeeMode.CLUSTER) {
|
|
||||||
return ((JedisClusterSummoner) this.plugin.getSummoner()).obtainResource();
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Mode is not " + RedisBungeeMode.CLUSTER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This gives you an instance of JedisPooled that can't be closed
|
|
||||||
* see {@link com.imaginarycode.minecraft.redisbungee.api.summoners.NotClosableJedisPooled}
|
|
||||||
*
|
|
||||||
* @return {@link redis.clients.jedis.JedisPooled}
|
|
||||||
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE}
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
public JedisPooled requestJedisPooled() {
|
|
||||||
if (getMode() == RedisBungeeMode.SINGLE) {
|
|
||||||
return ((JedisPooledSummoner) this.plugin.getSummoner()).obtainResource();
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Mode is not " + RedisBungeeMode.SINGLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns Summoner class responsible for Single Jedis {@link redis.clients.jedis.JedisPooled} with {@link JedisPool}, Cluster Jedis {@link redis.clients.jedis.JedisCluster} handling
|
|
||||||
*
|
|
||||||
* @return {@link Summoner}
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
public Summoner<?> getSummoner() {
|
|
||||||
return this.plugin.getSummoner();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* shows what mode is RedisBungee is on
|
|
||||||
*
|
|
||||||
* @return {@link RedisBungeeMode}
|
|
||||||
* @since 0.8.0
|
|
||||||
*/
|
|
||||||
public RedisBungeeMode getMode() {
|
|
||||||
return this.plugin.getRedisBungeeMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AbstractRedisBungeeAPI getAbstractRedisBungeeAPI() {
|
|
||||||
return abstractRedisBungeeAPI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,310 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api;
|
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.net.InetAddresses;
|
|
||||||
import com.google.common.reflect.TypeToken;
|
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class manages all the data that RedisBungee fetches from Redis, along with updates to that data.
|
|
||||||
*
|
|
||||||
* @since 0.3.3
|
|
||||||
*/
|
|
||||||
public abstract class AbstractDataManager<P, PL, PD, PS> {
|
|
||||||
protected final RedisBungeePlugin<P> plugin;
|
|
||||||
private final Cache<UUID, String> serverCache = createCache();
|
|
||||||
private final Cache<UUID, String> proxyCache = createCache();
|
|
||||||
private final Cache<UUID, InetAddress> ipCache = createCache();
|
|
||||||
private final Cache<UUID, Long> lastOnlineCache = createCache();
|
|
||||||
private final Gson gson = new Gson();
|
|
||||||
|
|
||||||
public AbstractDataManager(RedisBungeePlugin<P> plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <K, V> Cache<K, V> createCache() {
|
|
||||||
// TODO: Allow customization via cache specification, ala ServerListPlus
|
|
||||||
return CacheBuilder.newBuilder()
|
|
||||||
.maximumSize(1000)
|
|
||||||
.expireAfterWrite(1, TimeUnit.HOURS)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServer(final UUID uuid) {
|
|
||||||
P player = plugin.getPlayer(uuid);
|
|
||||||
|
|
||||||
if (player != null)
|
|
||||||
return plugin.isPlayerOnAServer(player) ? plugin.getPlayerServerName(player) : null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return serverCache.get(uuid, new RedisTask<String>(plugin) {
|
|
||||||
@Override
|
|
||||||
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "server"), "user not found");
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (ExecutionException | UncheckedExecutionException e) {
|
|
||||||
if (e.getCause() instanceof NullPointerException && e.getCause().getMessage().equals("user not found"))
|
|
||||||
return null; // HACK
|
|
||||||
plugin.logFatal("Unable to get server");
|
|
||||||
throw new RuntimeException("Unable to get server for " + uuid, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getProxy(final UUID uuid) {
|
|
||||||
P player = plugin.getPlayer(uuid);
|
|
||||||
|
|
||||||
if (player != null)
|
|
||||||
return plugin.getConfiguration().getProxyId();
|
|
||||||
|
|
||||||
try {
|
|
||||||
return proxyCache.get(uuid, new RedisTask<String>(plugin) {
|
|
||||||
@Override
|
|
||||||
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "proxy"), "user not found");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (ExecutionException | UncheckedExecutionException e) {
|
|
||||||
if (e.getCause() instanceof NullPointerException && e.getCause().getMessage().equals("user not found"))
|
|
||||||
return null; // HACK
|
|
||||||
plugin.logFatal("Unable to get proxy");
|
|
||||||
throw new RuntimeException("Unable to get proxy for " + uuid, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetAddress getIp(final UUID uuid) {
|
|
||||||
P player = plugin.getPlayer(uuid);
|
|
||||||
|
|
||||||
if (player != null)
|
|
||||||
return plugin.getPlayerIp(player);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return ipCache.get(uuid, new RedisTask<InetAddress>(plugin) {
|
|
||||||
@Override
|
|
||||||
public InetAddress unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
String result = unifiedJedis.hget("player:" + uuid, "ip");
|
|
||||||
if (result == null)
|
|
||||||
throw new NullPointerException("user not found");
|
|
||||||
return InetAddresses.forString(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (ExecutionException | UncheckedExecutionException e) {
|
|
||||||
if (e.getCause() instanceof NullPointerException && e.getCause().getMessage().equals("user not found"))
|
|
||||||
return null; // HACK
|
|
||||||
plugin.logFatal("Unable to get IP");
|
|
||||||
throw new RuntimeException("Unable to get IP for " + uuid, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastOnline(final UUID uuid) {
|
|
||||||
P player = plugin.getPlayer(uuid);
|
|
||||||
|
|
||||||
if (player != null)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
String result = unifiedJedis.hget("player:" + uuid, "online");
|
|
||||||
return result == null ? -1 : Long.parseLong(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
plugin.logFatal("Unable to get last time online");
|
|
||||||
throw new RuntimeException("Unable to get last time online for " + uuid, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void invalidate(UUID uuid) {
|
|
||||||
ipCache.invalidate(uuid);
|
|
||||||
lastOnlineCache.invalidate(uuid);
|
|
||||||
serverCache.invalidate(uuid);
|
|
||||||
proxyCache.invalidate(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invalidate all entries related to this player, since they now lie. (call invalidate(uuid))
|
|
||||||
public abstract void onPostLogin(PL event);
|
|
||||||
|
|
||||||
// Invalidate all entries related to this player, since they now lie. (call invalidate(uuid))
|
|
||||||
public abstract void onPlayerDisconnect(PD event);
|
|
||||||
|
|
||||||
public abstract void onPubSubMessage(PS event);
|
|
||||||
|
|
||||||
public abstract boolean handleKick(UUID target, String message);
|
|
||||||
|
|
||||||
protected void handlePubSubMessage(String channel, String message) {
|
|
||||||
if (!channel.equals("redisbungee-data"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Partially deserialize the message so we can look at the action
|
|
||||||
JsonObject jsonObject = JsonParser.parseString(message).getAsJsonObject();
|
|
||||||
|
|
||||||
final String source = jsonObject.get("source").getAsString();
|
|
||||||
|
|
||||||
if (source.equals(plugin.getConfiguration().getProxyId()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
DataManagerMessage.Action action = DataManagerMessage.Action.valueOf(jsonObject.get("action").getAsString());
|
|
||||||
|
|
||||||
switch (action) {
|
|
||||||
case JOIN:
|
|
||||||
final DataManagerMessage<LoginPayload> message1 = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<LoginPayload>>() {
|
|
||||||
}.getType());
|
|
||||||
proxyCache.put(message1.getTarget(), message1.getSource());
|
|
||||||
lastOnlineCache.put(message1.getTarget(), (long) 0);
|
|
||||||
ipCache.put(message1.getTarget(), message1.getPayload().getAddress());
|
|
||||||
plugin.executeAsync(() -> {
|
|
||||||
Object event = plugin.createPlayerJoinedNetworkEvent(message1.getTarget());
|
|
||||||
plugin.fireEvent(event);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case LEAVE:
|
|
||||||
final DataManagerMessage<LogoutPayload> message2 = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<LogoutPayload>>() {
|
|
||||||
}.getType());
|
|
||||||
invalidate(message2.getTarget());
|
|
||||||
lastOnlineCache.put(message2.getTarget(), message2.getPayload().getTimestamp());
|
|
||||||
plugin.executeAsync(() -> {
|
|
||||||
Object event = plugin.createPlayerLeftNetworkEvent(message2.getTarget());
|
|
||||||
plugin.fireEvent(event);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case SERVER_CHANGE:
|
|
||||||
final DataManagerMessage<ServerChangePayload> message3 = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<ServerChangePayload>>() {
|
|
||||||
}.getType());
|
|
||||||
serverCache.put(message3.getTarget(), message3.getPayload().getServer());
|
|
||||||
plugin.executeAsync(() -> {
|
|
||||||
Object event = plugin.createPlayerChangedServerNetworkEvent(message3.getTarget(), message3.getPayload().getOldServer(), message3.getPayload().getServer());
|
|
||||||
plugin.fireEvent(event);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case KICK:
|
|
||||||
final DataManagerMessage<KickPayload> kickPayload = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<KickPayload>>() {
|
|
||||||
}.getType());
|
|
||||||
plugin.executeAsync(() -> handleKick(kickPayload.target, kickPayload.payload.message));
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DataManagerMessage<T extends Payload> {
|
|
||||||
private final UUID target;
|
|
||||||
private final String source;
|
|
||||||
private final Action action; // for future use!
|
|
||||||
private final T payload;
|
|
||||||
|
|
||||||
public DataManagerMessage(UUID target, String source, Action action, T payload) {
|
|
||||||
this.target = target;
|
|
||||||
this.source = source;
|
|
||||||
this.action = action;
|
|
||||||
this.payload = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getTarget() {
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSource() {
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Action getAction() {
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getPayload() {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Action {
|
|
||||||
JOIN,
|
|
||||||
LEAVE,
|
|
||||||
KICK,
|
|
||||||
SERVER_CHANGE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static abstract class Payload {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class KickPayload extends Payload {
|
|
||||||
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
public KickPayload(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class LoginPayload extends Payload {
|
|
||||||
private final InetAddress address;
|
|
||||||
|
|
||||||
public LoginPayload(InetAddress address) {
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetAddress getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ServerChangePayload extends Payload {
|
|
||||||
private final String server;
|
|
||||||
private final String oldServer;
|
|
||||||
|
|
||||||
public ServerChangePayload(String server, String oldServer) {
|
|
||||||
this.server = server;
|
|
||||||
this.oldServer = oldServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOldServer() {
|
|
||||||
return oldServer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static class LogoutPayload extends Payload {
|
|
||||||
private final long timestamp;
|
|
||||||
|
|
||||||
public LogoutPayload(long timestamp) {
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api;
|
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.common.collect.Multiset;
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class AbstractRedisBungeeListener<LE, PLE, PD, SC, PP, PM, PS> {
|
|
||||||
|
|
||||||
protected final RedisBungeePlugin<?> plugin;
|
|
||||||
protected final List<InetAddress> exemptAddresses;
|
|
||||||
protected final Gson gson = new Gson();
|
|
||||||
|
|
||||||
public AbstractRedisBungeeListener(RedisBungeePlugin<?> plugin, List<InetAddress> exemptAddresses) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.exemptAddresses = exemptAddresses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onLogin(LE event) {}
|
|
||||||
|
|
||||||
public abstract void onPostLogin(PLE event);
|
|
||||||
|
|
||||||
public abstract void onPlayerDisconnect(PD event);
|
|
||||||
|
|
||||||
public abstract void onServerChange(SC event);
|
|
||||||
|
|
||||||
public abstract void onPing(PP event);
|
|
||||||
|
|
||||||
public abstract void onPluginMessage(PM event);
|
|
||||||
|
|
||||||
public abstract void onPubSubMessage(PS event);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api;
|
|
||||||
|
|
||||||
|
|
||||||
import redis.clients.jedis.JedisPubSub;
|
|
||||||
|
|
||||||
|
|
||||||
public class JedisPubSubHandler extends JedisPubSub {
|
|
||||||
|
|
||||||
private final RedisBungeePlugin<?> plugin;
|
|
||||||
|
|
||||||
public JedisPubSubHandler(RedisBungeePlugin<?> plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(final String s, final String s2) {
|
|
||||||
if (s2.trim().length() == 0) return;
|
|
||||||
plugin.executeAsync(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Object event = plugin.createPubSubEvent(s, s2);
|
|
||||||
plugin.fireEvent(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisCluster;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class PubSubListener implements Runnable {
|
|
||||||
private JedisPubSubHandler jpsh;
|
|
||||||
private final Set<String> addedChannels = new HashSet<String>();
|
|
||||||
|
|
||||||
private final RedisBungeePlugin<?> plugin;
|
|
||||||
|
|
||||||
public PubSubListener(RedisBungeePlugin<?> plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
RedisTask<Void> subTask = new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
jpsh = new JedisPubSubHandler(plugin);
|
|
||||||
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
|
|
||||||
addedChannels.add("redisbungee-allservers");
|
|
||||||
addedChannels.add("redisbungee-data");
|
|
||||||
unifiedJedis.subscribe(jpsh, addedChannels.toArray(new String[0]));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
subTask.execute();
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.logWarn("PubSub error, attempting to recover in 5 secs.");
|
|
||||||
plugin.executeAsyncAfter(this, TimeUnit.SECONDS, 5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addChannel(String... channel) {
|
|
||||||
addedChannels.addAll(Arrays.asList(channel));
|
|
||||||
jpsh.subscribe(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeChannel(String... channel) {
|
|
||||||
Arrays.asList(channel).forEach(addedChannels::remove);
|
|
||||||
jpsh.unsubscribe(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void poison() {
|
|
||||||
addedChannels.clear();
|
|
||||||
jpsh.unsubscribe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api;
|
|
||||||
|
|
||||||
public enum RedisBungeeMode {
|
|
||||||
SINGLE, CLUSTER
|
|
||||||
}
|
|
||||||
@@ -1,273 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.EventsPlatform;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator;
|
|
||||||
import redis.clients.jedis.Protocol;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This Class has all internal methods needed by every redis bungee plugin, and it can be used to implement another platforms than bungeecord or another forks of RedisBungee
|
|
||||||
*
|
|
||||||
* @author Ham1255
|
|
||||||
* @since 0.7.0
|
|
||||||
*/
|
|
||||||
public interface RedisBungeePlugin<P> extends EventsPlatform {
|
|
||||||
|
|
||||||
default void initialize() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
default void stop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Summoner<?> getSummoner();
|
|
||||||
|
|
||||||
RedisBungeeConfiguration getConfiguration();
|
|
||||||
|
|
||||||
int getCount();
|
|
||||||
|
|
||||||
default int getCurrentCount() {
|
|
||||||
return new RedisTask<Long>(this) {
|
|
||||||
@Override
|
|
||||||
public Long unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
long total = 0;
|
|
||||||
long redisTime = getRedisTime(unifiedJedis);
|
|
||||||
Map<String, String> heartBeats = unifiedJedis.hgetAll("heartbeats");
|
|
||||||
for (Map.Entry<String, String> stringStringEntry : heartBeats.entrySet()) {
|
|
||||||
String k = stringStringEntry.getKey();
|
|
||||||
String v = stringStringEntry.getValue();
|
|
||||||
|
|
||||||
long heartbeatTime = Long.parseLong(v);
|
|
||||||
if (heartbeatTime + RedisUtil.PROXY_TIMEOUT >= redisTime) {
|
|
||||||
total = total + unifiedJedis.scard("proxy:" + k + ":usersOnline");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
}.execute().intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> getLocalPlayersAsUuidStrings();
|
|
||||||
|
|
||||||
AbstractDataManager<P, ?, ?, ?> getDataManager();
|
|
||||||
|
|
||||||
default Set<UUID> getPlayers() {
|
|
||||||
return new RedisTask<Set<UUID>>(this) {
|
|
||||||
@Override
|
|
||||||
public Set<UUID> unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
|
||||||
try {
|
|
||||||
List<String> keys = new ArrayList<>();
|
|
||||||
for (String i : getProxiesIds()) {
|
|
||||||
keys.add("proxy:" + i + ":usersOnline");
|
|
||||||
}
|
|
||||||
if (!keys.isEmpty()) {
|
|
||||||
Set<String> users = unifiedJedis.sunion(keys.toArray(new String[0]));
|
|
||||||
if (users != null && !users.isEmpty()) {
|
|
||||||
for (String user : users) {
|
|
||||||
try {
|
|
||||||
setBuilder = setBuilder.add(UUID.fromString(user));
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JedisConnectionException e) {
|
|
||||||
// Redis server has disappeared!
|
|
||||||
logFatal("Unable to get connection from pool - did your Redis server go away?");
|
|
||||||
throw new RuntimeException("Unable to get all players online", e);
|
|
||||||
}
|
|
||||||
return setBuilder.build();
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractRedisBungeeAPI getAbstractRedisBungeeApi();
|
|
||||||
|
|
||||||
UUIDTranslator getUuidTranslator();
|
|
||||||
|
|
||||||
Multimap<String, UUID> serverToPlayersCache();
|
|
||||||
|
|
||||||
default Multimap<String, UUID> serversToPlayers() {
|
|
||||||
return new RedisTask<Multimap<String, UUID>>(this) {
|
|
||||||
@Override
|
|
||||||
public Multimap<String, UUID> unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
|
||||||
for (String serverId : getProxiesIds()) {
|
|
||||||
Set<String> players = unifiedJedis.smembers("proxy:" + serverId + ":usersOnline");
|
|
||||||
for (String player : players) {
|
|
||||||
String playerServer = unifiedJedis.hget("player:" + player, "server");
|
|
||||||
if (playerServer == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
builder.put(playerServer, UUID.fromString(player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
default Set<UUID> getPlayersOnProxy(String proxyId) {
|
|
||||||
checkArgument(getProxiesIds().contains(proxyId), proxyId + " is not a valid proxy ID");
|
|
||||||
return new RedisTask<Set<UUID>>(this) {
|
|
||||||
@Override
|
|
||||||
public Set<UUID> unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
Set<String> users = unifiedJedis.smembers("proxy:" + proxyId + ":usersOnline");
|
|
||||||
ImmutableSet.Builder<UUID> builder = ImmutableSet.builder();
|
|
||||||
for (String user : users) {
|
|
||||||
builder.add(UUID.fromString(user));
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
default void sendProxyCommand(String proxyId, String command) {
|
|
||||||
checkArgument(getProxiesIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
|
|
||||||
sendChannelMessage("redisbungee-" + proxyId, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> getProxiesIds();
|
|
||||||
|
|
||||||
default List<String> getCurrentProxiesIds(boolean lagged) {
|
|
||||||
return new RedisTask<List<String>>(this) {
|
|
||||||
@Override
|
|
||||||
public List<String> unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
try {
|
|
||||||
long time = getRedisTime(unifiedJedis);
|
|
||||||
ImmutableList.Builder<String> servers = ImmutableList.builder();
|
|
||||||
Map<String, String> heartbeats = unifiedJedis.hgetAll("heartbeats");
|
|
||||||
for (Map.Entry<String, String> entry : heartbeats.entrySet()) {
|
|
||||||
try {
|
|
||||||
long stamp = Long.parseLong(entry.getValue());
|
|
||||||
if (lagged ? time >= stamp + RedisUtil.PROXY_TIMEOUT : time <= stamp + RedisUtil.PROXY_TIMEOUT) {
|
|
||||||
servers.add(entry.getKey());
|
|
||||||
} else if (time > stamp + RedisUtil.PROXY_TIMEOUT) {
|
|
||||||
logWarn(entry.getKey() + " is " + (time - stamp) + " seconds behind! (Time not synchronized or server down?) and was removed from heartbeat.");
|
|
||||||
unifiedJedis.hdel("heartbeats", entry.getKey());
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return servers.build();
|
|
||||||
} catch (JedisConnectionException e) {
|
|
||||||
logFatal("Unable to fetch server IDs");
|
|
||||||
e.printStackTrace();
|
|
||||||
return Collections.singletonList(getConfiguration().getProxyId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
PubSubListener getPubSubListener();
|
|
||||||
|
|
||||||
default void sendChannelMessage(String channel, String message) {
|
|
||||||
new RedisTask<Void>(this) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
try {
|
|
||||||
unifiedJedis.publish(channel, message);
|
|
||||||
} catch (JedisConnectionException e) {
|
|
||||||
// Redis server has disappeared!
|
|
||||||
logFatal("Unable to get connection from pool - did your Redis server go away?");
|
|
||||||
throw new RuntimeException("Unable to publish channel message", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
void executeAsync(Runnable runnable);
|
|
||||||
|
|
||||||
void executeAsyncAfter(Runnable runnable, TimeUnit timeUnit, int time);
|
|
||||||
|
|
||||||
boolean isOnlineMode();
|
|
||||||
|
|
||||||
void logInfo(String msg);
|
|
||||||
|
|
||||||
void logWarn(String msg);
|
|
||||||
|
|
||||||
void logFatal(String msg);
|
|
||||||
|
|
||||||
P getPlayer(UUID uuid);
|
|
||||||
|
|
||||||
P getPlayer(String name);
|
|
||||||
|
|
||||||
UUID getPlayerUUID(String player);
|
|
||||||
|
|
||||||
String getPlayerName(UUID player);
|
|
||||||
|
|
||||||
String getPlayerServerName(P player);
|
|
||||||
|
|
||||||
boolean isPlayerOnAServer(P player);
|
|
||||||
|
|
||||||
InetAddress getPlayerIp(P player);
|
|
||||||
|
|
||||||
default void sendProxyCommand(String cmd) {
|
|
||||||
sendProxyCommand(getConfiguration().getProxyId(), cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
default Long getRedisTime(UnifiedJedis unifiedJedis) {
|
|
||||||
List<Object> data = (List<Object>) unifiedJedis.sendCommand(Protocol.Command.TIME);
|
|
||||||
List<String> times = new ArrayList<>();
|
|
||||||
data.forEach((o) -> times.add(new String((byte[])o)));
|
|
||||||
return getRedisTime(times);
|
|
||||||
}
|
|
||||||
default long getRedisTime(List<String> timeRes) {
|
|
||||||
return Long.parseLong(timeRes.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
default void kickPlayer(UUID playerUniqueId, String message) {
|
|
||||||
// first handle on origin proxy if player not found publish the payload
|
|
||||||
if (!getDataManager().handleKick(playerUniqueId, message)) {
|
|
||||||
new RedisTask<Void>(this) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
PayloadUtils.kickPlayerPayload(playerUniqueId, message, unifiedJedis);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default void kickPlayer(String playerName, String message) {
|
|
||||||
// fetch the uuid from name
|
|
||||||
UUID playerUUID = getUuidTranslator().getTranslatedUuid(playerName, true);
|
|
||||||
kickPlayer(playerUUID, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
RedisBungeeMode getRedisBungeeMode();
|
|
||||||
|
|
||||||
void updateProxiesIds();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.config;
|
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.reflect.TypeToken;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
|
||||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
|
||||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
|
||||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
|
||||||
import redis.clients.jedis.*;
|
|
||||||
import redis.clients.jedis.providers.ClusterConnectionProvider;
|
|
||||||
import redis.clients.jedis.providers.PooledConnectionProvider;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public interface ConfigLoader {
|
|
||||||
|
|
||||||
default void loadConfig(RedisBungeePlugin<?> plugin, File dataFolder) throws IOException {
|
|
||||||
loadConfig(plugin, dataFolder.toPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
default void loadConfig(RedisBungeePlugin<?> plugin, Path dataFolder) throws IOException {
|
|
||||||
Path configFile = createConfigFile(dataFolder);
|
|
||||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
|
||||||
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
|
||||||
if (node.getNode("config-version").getInt(0) != RedisBungeeConfiguration.CONFIG_VERSION) {
|
|
||||||
handleOldConfig(dataFolder);
|
|
||||||
node = yamlConfigurationFileLoader.load();
|
|
||||||
}
|
|
||||||
final boolean useSSL = node.getNode("useSSL").getBoolean(false);
|
|
||||||
final boolean overrideBungeeCommands = node.getNode("override-bungee-commands").getBoolean(false);
|
|
||||||
final boolean registerLegacyCommands = node.getNode("register-legacy-commands").getBoolean(false);
|
|
||||||
final boolean restoreOldKickBehavior = node.getNode("disable-kick-when-online").getBoolean(false);
|
|
||||||
String redisPassword = node.getNode("redis-password").getString("");
|
|
||||||
String proxyId = node.getNode("proxy-id").getString("test-1");
|
|
||||||
final int maxConnections = node.getNode("max-redis-connections").getInt(10);
|
|
||||||
List<String> exemptAddresses;
|
|
||||||
try {
|
|
||||||
exemptAddresses = node.getNode("exempt-ip-addresses").getList(TypeToken.of(String.class));
|
|
||||||
} catch (ObjectMappingException e) {
|
|
||||||
exemptAddresses = Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check redis password
|
|
||||||
if ((redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
|
||||||
redisPassword = null;
|
|
||||||
plugin.logWarn("password is empty");
|
|
||||||
}
|
|
||||||
if (useSSL) {
|
|
||||||
plugin.logInfo("Using ssl");
|
|
||||||
}
|
|
||||||
// Configuration sanity checks.
|
|
||||||
if (proxyId == null || proxyId.isEmpty()) {
|
|
||||||
String genId = UUID.randomUUID().toString();
|
|
||||||
plugin.logInfo("Generated proxy id " + genId + " and saving it to config.");
|
|
||||||
node.getNode("proxy-id").setValue(genId);
|
|
||||||
yamlConfigurationFileLoader.save(node);
|
|
||||||
proxyId = genId;
|
|
||||||
plugin.logInfo("proxy id was generated: " + proxyId);
|
|
||||||
} else {
|
|
||||||
plugin.logInfo("Loaded proxy id " + proxyId);
|
|
||||||
}
|
|
||||||
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, getMessagesFromPath(createMessagesFile(dataFolder)), restoreOldKickBehavior);
|
|
||||||
Summoner<?> summoner;
|
|
||||||
RedisBungeeMode redisBungeeMode;
|
|
||||||
if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
|
|
||||||
plugin.logInfo("RedisBungee MODE: CLUSTER");
|
|
||||||
Set<HostAndPort> hostAndPortSet = new HashSet<>();
|
|
||||||
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
|
||||||
poolConfig.setMaxTotal(maxConnections);
|
|
||||||
poolConfig.setBlockWhenExhausted(true);
|
|
||||||
node.getNode("redis-cluster-servers").getChildrenList().forEach((childNode) -> {
|
|
||||||
Map<Object, ? extends ConfigurationNode> hostAndPort = childNode.getChildrenMap();
|
|
||||||
String host = hostAndPort.get("host").getString();
|
|
||||||
int port = hostAndPort.get("port").getInt();
|
|
||||||
hostAndPortSet.add(new HostAndPort(host, port));
|
|
||||||
});
|
|
||||||
plugin.logInfo(hostAndPortSet.size() + " cluster nodes were specified");
|
|
||||||
if (hostAndPortSet.isEmpty()) {
|
|
||||||
throw new RuntimeException("No redis cluster servers specified");
|
|
||||||
}
|
|
||||||
summoner = new JedisClusterSummoner(new ClusterConnectionProvider(hostAndPortSet, DefaultJedisClientConfig.builder().password(redisPassword).ssl(useSSL).socketTimeoutMillis(5000).timeoutMillis(10000).build(), poolConfig));
|
|
||||||
redisBungeeMode = RedisBungeeMode.CLUSTER;
|
|
||||||
} else {
|
|
||||||
plugin.logInfo("RedisBungee MODE: SINGLE");
|
|
||||||
final String redisServer = node.getNode("redis-server").getString("127.0.0.1");
|
|
||||||
final int redisPort = node.getNode("redis-port").getInt(6379);
|
|
||||||
if (redisServer != null && redisServer.isEmpty()) {
|
|
||||||
throw new RuntimeException("No redis server specified");
|
|
||||||
}
|
|
||||||
JedisPool jedisPool = null;
|
|
||||||
if (node.getNode("enable-jedis-pool-compatibility").getBoolean(true)) {
|
|
||||||
JedisPoolConfig config = new JedisPoolConfig();
|
|
||||||
config.setMaxTotal(node.getNode("compatibility-max-connections").getInt(3));
|
|
||||||
config.setBlockWhenExhausted(true);
|
|
||||||
jedisPool = new JedisPool(config, redisServer, redisPort, 5000, redisPassword, useSSL);
|
|
||||||
plugin.logInfo("Compatibility JedisPool was created");
|
|
||||||
}
|
|
||||||
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
|
||||||
poolConfig.setMaxTotal(maxConnections);
|
|
||||||
poolConfig.setBlockWhenExhausted(true);
|
|
||||||
summoner = new JedisPooledSummoner(new PooledConnectionProvider(new ConnectionFactory(new HostAndPort(redisServer, redisPort), DefaultJedisClientConfig.builder().timeoutMillis(5000).ssl(useSSL).password(redisPassword).build()), poolConfig), jedisPool);
|
|
||||||
redisBungeeMode = RedisBungeeMode.SINGLE;
|
|
||||||
}
|
|
||||||
plugin.logInfo("Successfully connected to Redis.");
|
|
||||||
onConfigLoad(configuration, summoner, redisBungeeMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onConfigLoad(RedisBungeeConfiguration configuration, Summoner<?> summoner, RedisBungeeMode mode);
|
|
||||||
|
|
||||||
default ImmutableMap<RedisBungeeConfiguration.MessageType, String> getMessagesFromPath(Path path) throws IOException {
|
|
||||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(path).build();
|
|
||||||
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
|
||||||
HashMap<RedisBungeeConfiguration.MessageType, String> messages = new HashMap<>();
|
|
||||||
messages.put(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION, node.getNode("logged-in-other-location").getString("§cLogged in from another location."));
|
|
||||||
messages.put(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN, node.getNode("already-logged-in").getString("§cYou are already logged in!"));
|
|
||||||
return ImmutableMap.copyOf(messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
default Path createMessagesFile(Path dataFolder) throws IOException {
|
|
||||||
if (Files.notExists(dataFolder)) {
|
|
||||||
Files.createDirectory(dataFolder);
|
|
||||||
}
|
|
||||||
Path file = dataFolder.resolve("messages.yml");
|
|
||||||
if (Files.notExists(file)) {
|
|
||||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream("messages.yml")) {
|
|
||||||
Files.createFile(file);
|
|
||||||
assert in != null;
|
|
||||||
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
default Path createConfigFile(Path dataFolder) throws IOException {
|
|
||||||
if (Files.notExists(dataFolder)) {
|
|
||||||
Files.createDirectory(dataFolder);
|
|
||||||
}
|
|
||||||
Path file = dataFolder.resolve("config.yml");
|
|
||||||
if (Files.notExists(file)) {
|
|
||||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream("config.yml")) {
|
|
||||||
Files.createFile(file);
|
|
||||||
assert in != null;
|
|
||||||
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
default void handleOldConfig(Path dataFolder) throws IOException {
|
|
||||||
Path oldConfigFolder = dataFolder.resolve("old_config");
|
|
||||||
if (Files.notExists(oldConfigFolder)) {
|
|
||||||
Files.createDirectory(oldConfigFolder);
|
|
||||||
}
|
|
||||||
Path oldConfigPath = dataFolder.resolve("config.yml");
|
|
||||||
Files.move(oldConfigPath, oldConfigFolder.resolve(UUID.randomUUID() + "_config.yml"));
|
|
||||||
createConfigFile(dataFolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.config;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.net.InetAddresses;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RedisBungeeConfiguration {
|
|
||||||
|
|
||||||
public enum MessageType {
|
|
||||||
LOGGED_IN_OTHER_LOCATION,
|
|
||||||
ALREADY_LOGGED_IN
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ImmutableMap<MessageType, String> messages;
|
|
||||||
public static final int CONFIG_VERSION = 1;
|
|
||||||
private final String proxyId;
|
|
||||||
private final List<InetAddress> exemptAddresses;
|
|
||||||
private final boolean registerLegacyCommands;
|
|
||||||
private final boolean overrideBungeeCommands;
|
|
||||||
|
|
||||||
private final boolean restoreOldKickBehavior;
|
|
||||||
|
|
||||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, ImmutableMap<MessageType, String> messages, boolean restoreOldKickBehavior) {
|
|
||||||
this.proxyId = proxyId;
|
|
||||||
this.messages = messages;
|
|
||||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
|
||||||
for (String s : exemptAddresses) {
|
|
||||||
addressBuilder.add(InetAddresses.forString(s));
|
|
||||||
}
|
|
||||||
this.exemptAddresses = addressBuilder.build();
|
|
||||||
this.registerLegacyCommands = registerLegacyCommands;
|
|
||||||
this.overrideBungeeCommands = overrideBungeeCommands;
|
|
||||||
this.restoreOldKickBehavior = restoreOldKickBehavior;
|
|
||||||
}
|
|
||||||
public String getProxyId() {
|
|
||||||
return proxyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<InetAddress> getExemptAddresses() {
|
|
||||||
return exemptAddresses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean doRegisterLegacyCommands() {
|
|
||||||
return registerLegacyCommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean doOverrideBungeeCommands() {
|
|
||||||
return overrideBungeeCommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImmutableMap<MessageType, String> getMessages() {
|
|
||||||
return messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean restoreOldKickBehavior() {
|
|
||||||
return restoreOldKickBehavior;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.events;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Since each platform have their own events' implementation for example Bungeecord events extends Event while velocity don't
|
|
||||||
*
|
|
||||||
* @author Ham1255
|
|
||||||
* @since 0.7.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface EventsPlatform {
|
|
||||||
|
|
||||||
IPlayerChangedServerNetworkEvent createPlayerChangedServerNetworkEvent(UUID uuid, String previousServer, String server);
|
|
||||||
|
|
||||||
IPlayerJoinedNetworkEvent createPlayerJoinedNetworkEvent(UUID uuid);
|
|
||||||
|
|
||||||
IPlayerLeftNetworkEvent createPlayerLeftNetworkEvent(UUID uuid);
|
|
||||||
|
|
||||||
IPubSubMessageEvent createPubSubEvent(String channel, String message);
|
|
||||||
|
|
||||||
void fireEvent(Object event);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.events;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface IPlayerChangedServerNetworkEvent extends RedisBungeeEvent {
|
|
||||||
|
|
||||||
UUID getUuid();
|
|
||||||
|
|
||||||
String getServer();
|
|
||||||
|
|
||||||
String getPreviousServer();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.events;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface IPlayerJoinedNetworkEvent extends RedisBungeeEvent {
|
|
||||||
|
|
||||||
UUID getUuid();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.events;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface IPlayerLeftNetworkEvent extends RedisBungeeEvent {
|
|
||||||
|
|
||||||
UUID getUuid();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.events;
|
|
||||||
|
|
||||||
public interface IPubSubMessageEvent extends RedisBungeeEvent {
|
|
||||||
|
|
||||||
String getChannel();
|
|
||||||
|
|
||||||
String getMessage();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.events;
|
|
||||||
|
|
||||||
interface RedisBungeeEvent {
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
|
||||||
|
|
||||||
import redis.clients.jedis.JedisCluster;
|
|
||||||
import redis.clients.jedis.providers.ClusterConnectionProvider;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class JedisClusterSummoner implements Summoner<JedisCluster> {
|
|
||||||
public final ClusterConnectionProvider clusterConnectionProvider;
|
|
||||||
|
|
||||||
public JedisClusterSummoner(ClusterConnectionProvider clusterConnectionProvider) {
|
|
||||||
this.clusterConnectionProvider = clusterConnectionProvider;
|
|
||||||
// test the connection
|
|
||||||
JedisCluster jedisCluster = obtainResource();
|
|
||||||
jedisCluster.set("random_data", "0");
|
|
||||||
jedisCluster.del("random_data");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
this.clusterConnectionProvider.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JedisCluster obtainResource() {
|
|
||||||
return new NotClosableJedisCluster(this.clusterConnectionProvider, 60, Duration.ofSeconds(30000));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisPool;
|
|
||||||
import redis.clients.jedis.JedisPooled;
|
|
||||||
import redis.clients.jedis.providers.PooledConnectionProvider;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class JedisPooledSummoner implements Summoner<JedisPooled> {
|
|
||||||
|
|
||||||
private final PooledConnectionProvider connectionProvider;
|
|
||||||
private final JedisPool jedisPool;
|
|
||||||
|
|
||||||
public JedisPooledSummoner(PooledConnectionProvider connectionProvider, JedisPool jedisPool) {
|
|
||||||
this.connectionProvider = connectionProvider;
|
|
||||||
this.jedisPool = jedisPool;
|
|
||||||
// test connections
|
|
||||||
if (jedisPool != null) {
|
|
||||||
try (Jedis jedis = this.jedisPool.getResource()) {
|
|
||||||
// Test the connection to make sure configuration is right
|
|
||||||
jedis.ping();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
final JedisPooled jedisPooled = this.obtainResource();
|
|
||||||
jedisPooled.set("random_data", "0");
|
|
||||||
jedisPooled.del("random_data");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JedisPooled obtainResource() {
|
|
||||||
// create UnClosable JedisPool *disposable*
|
|
||||||
return new NotClosableJedisPooled(this.connectionProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JedisPool getCompatibilityJedisPool() {
|
|
||||||
return this.jedisPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
if (this.jedisPool != null) {
|
|
||||||
this.jedisPool.close();
|
|
||||||
}
|
|
||||||
this.connectionProvider.close();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
|
||||||
|
|
||||||
import redis.clients.jedis.JedisCluster;
|
|
||||||
import redis.clients.jedis.JedisPooled;
|
|
||||||
import redis.clients.jedis.providers.ClusterConnectionProvider;
|
|
||||||
import redis.clients.jedis.providers.PooledConnectionProvider;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
|
|
||||||
public class NotClosableJedisCluster extends JedisCluster {
|
|
||||||
|
|
||||||
NotClosableJedisCluster(ClusterConnectionProvider provider, int maxAttempts, Duration maxTotalRetriesDuration) {
|
|
||||||
super(provider, maxAttempts, maxTotalRetriesDuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
|
||||||
|
|
||||||
import redis.clients.jedis.JedisPooled;
|
|
||||||
import redis.clients.jedis.providers.PooledConnectionProvider;
|
|
||||||
|
|
||||||
|
|
||||||
public class NotClosableJedisPooled extends JedisPooled {
|
|
||||||
NotClosableJedisPooled(PooledConnectionProvider provider) {
|
|
||||||
super(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class intended for future release to support redis sentinel or redis clusters
|
|
||||||
*
|
|
||||||
* @author Ham1255
|
|
||||||
* @since 0.7.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface Summoner<P> extends Closeable {
|
|
||||||
|
|
||||||
P obtainResource();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.tasks;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisCluster;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public class HeartbeatTask extends RedisTask<Void>{
|
|
||||||
|
|
||||||
public final static TimeUnit REPEAT_INTERVAL_TIME_UNIT = TimeUnit.SECONDS;
|
|
||||||
public final static int INTERVAL = 1;
|
|
||||||
private final AtomicInteger globalPlayerCount;
|
|
||||||
|
|
||||||
public HeartbeatTask(RedisBungeePlugin<?> plugin, AtomicInteger globalPlayerCount) {
|
|
||||||
super(plugin);
|
|
||||||
this.globalPlayerCount = globalPlayerCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
try {
|
|
||||||
long redisTime = plugin.getRedisTime(unifiedJedis);
|
|
||||||
unifiedJedis.hset("heartbeats", plugin.getConfiguration().getProxyId(), String.valueOf(redisTime));
|
|
||||||
} catch (JedisConnectionException e) {
|
|
||||||
// Redis server has disappeared!
|
|
||||||
plugin.logFatal("Unable to update heartbeat - did your Redis server go away?");
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
plugin.updateProxiesIds();
|
|
||||||
globalPlayerCount.set(plugin.getCurrentCount());
|
|
||||||
} catch (Throwable e) {
|
|
||||||
plugin.logFatal("Unable to update data - did your Redis server go away?");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.tasks;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil;
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisCluster;
|
|
||||||
import redis.clients.jedis.Protocol;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public class InitialUtils {
|
|
||||||
|
|
||||||
public static void checkRedisVersion(RedisBungeePlugin<?> plugin) {
|
|
||||||
new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
// This is more portable than INFO <section>
|
|
||||||
|
|
||||||
String info = new String((byte[]) unifiedJedis.sendCommand(Protocol.Command.INFO));
|
|
||||||
for (String s : info.split("\r\n")) {
|
|
||||||
if (s.startsWith("redis_version:")) {
|
|
||||||
String version = s.split(":")[1];
|
|
||||||
plugin.logInfo(version + " <- redis version");
|
|
||||||
if (!RedisUtil.isRedisVersionRight(version)) {
|
|
||||||
plugin.logFatal("Your version of Redis (" + version + ") is not at least version 3.0 RedisBungee requires a newer version of Redis.");
|
|
||||||
throw new RuntimeException("Unsupported Redis version detected");
|
|
||||||
}
|
|
||||||
long uuidCacheSize = unifiedJedis.hlen("uuid-cache");
|
|
||||||
if (uuidCacheSize > 750000) {
|
|
||||||
plugin.logInfo("Looks like you have a really big UUID cache! Run https://github.com/ProxioDev/Brains");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void checkIfRecovering(RedisBungeePlugin<?> plugin, Path dataFolder) {
|
|
||||||
new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
Path crashFile = dataFolder.resolve("restarted_from_crash.txt");
|
|
||||||
if (Files.exists(crashFile)) {
|
|
||||||
try {
|
|
||||||
Files.delete(crashFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
plugin.logInfo("crash file was deleted");
|
|
||||||
} else if (unifiedJedis.hexists("heartbeats", plugin.getConfiguration().getProxyId())) {
|
|
||||||
try {
|
|
||||||
long value = Long.parseLong(unifiedJedis.hget("heartbeats", plugin.getConfiguration().getProxyId()));
|
|
||||||
long redisTime = plugin.getRedisTime(unifiedJedis);
|
|
||||||
|
|
||||||
if (redisTime < value + RedisUtil.PROXY_TIMEOUT) {
|
|
||||||
logImposter(plugin);
|
|
||||||
throw new RuntimeException("Possible impostor instance!");
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void logImposter(RedisBungeePlugin<?> plugin) {
|
|
||||||
plugin.logFatal("You have launched a possible impostor Velocity / Bungeecord instance. Another instance is already running.");
|
|
||||||
plugin.logFatal("For data consistency reasons, RedisBungee will now disable itself.");
|
|
||||||
plugin.logFatal("If this instance is coming up from a crash, create a file in your RedisBungee plugins directory with the name 'restarted_from_crash.txt' and RedisBungee will not perform this check.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.tasks;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public abstract class IntegrityCheckTask extends RedisTask<Void> {
|
|
||||||
|
|
||||||
public static int INTERVAL = 30;
|
|
||||||
public static TimeUnit TIMEUNIT = TimeUnit.SECONDS;
|
|
||||||
|
|
||||||
|
|
||||||
public IntegrityCheckTask(RedisBungeePlugin<?> plugin) {
|
|
||||||
super(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
try {
|
|
||||||
Set<String> players = plugin.getLocalPlayersAsUuidStrings();
|
|
||||||
Set<String> playersInRedis = unifiedJedis.smembers("proxy:" + plugin.getConfiguration().getProxyId() + ":usersOnline");
|
|
||||||
List<String> lagged = plugin.getCurrentProxiesIds(true);
|
|
||||||
|
|
||||||
// Clean up lagged players.
|
|
||||||
for (String s : lagged) {
|
|
||||||
Set<String> laggedPlayers = unifiedJedis.smembers("proxy:" + s + ":usersOnline");
|
|
||||||
unifiedJedis.del("proxy:" + s + ":usersOnline");
|
|
||||||
if (!laggedPlayers.isEmpty()) {
|
|
||||||
plugin.logInfo("Cleaning up lagged proxy " + s + " (" + laggedPlayers.size() + " players)...");
|
|
||||||
for (String laggedPlayer : laggedPlayers) {
|
|
||||||
PlayerUtils.cleanUpPlayer(laggedPlayer, unifiedJedis, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> absentLocally = new HashSet<>(playersInRedis);
|
|
||||||
absentLocally.removeAll(players);
|
|
||||||
Set<String> absentInRedis = new HashSet<>(players);
|
|
||||||
absentInRedis.removeAll(playersInRedis);
|
|
||||||
|
|
||||||
for (String member : absentLocally) {
|
|
||||||
boolean found = false;
|
|
||||||
for (String proxyId : plugin.getProxiesIds()) {
|
|
||||||
if (proxyId.equals(plugin.getConfiguration().getProxyId())) continue;
|
|
||||||
if (unifiedJedis.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
|
||||||
// Just clean up the set.
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
PlayerUtils.cleanUpPlayer(member, unifiedJedis, false);
|
|
||||||
plugin.logWarn("Player found in set that was not found locally and globally: " + member);
|
|
||||||
} else {
|
|
||||||
unifiedJedis.srem("proxy:" + plugin.getConfiguration().getProxyId() + ":usersOnline", member);
|
|
||||||
plugin.logWarn("Player found in set that was not found locally, but is on another proxy: " + member);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// due unifiedJedis does not support pipelined.
|
|
||||||
//Pipeline pipeline = jedis.pipelined();
|
|
||||||
|
|
||||||
for (String player : absentInRedis) {
|
|
||||||
// Player not online according to Redis but not BungeeCord.
|
|
||||||
handlePlatformPlayer(player, unifiedJedis);
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
plugin.logFatal("Unable to fix up stored player data");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public abstract void handlePlatformPlayer(String player, UnifiedJedis unifiedJedis);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.tasks;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
public abstract class RedisTask<V> implements Runnable, Callable<V> {
|
|
||||||
|
|
||||||
protected final Summoner<?> summoner;
|
|
||||||
protected final AbstractRedisBungeeAPI api;
|
|
||||||
protected RedisBungeePlugin<?> plugin;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V call() throws Exception {
|
|
||||||
return execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RedisTask(AbstractRedisBungeeAPI api) {
|
|
||||||
this.api = api;
|
|
||||||
this.summoner = api.getSummoner();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RedisTask(RedisBungeePlugin<?> plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.api = plugin.getAbstractRedisBungeeApi();
|
|
||||||
this.summoner = api.getSummoner();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract V unifiedJedisTask(UnifiedJedis unifiedJedis);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
this.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
public V execute(){
|
|
||||||
// JedisCluster, JedisPooled in fact is just UnifiedJedis does not need new instance since its single instance anyway.
|
|
||||||
if (api.getMode() == RedisBungeeMode.SINGLE) {
|
|
||||||
JedisPooledSummoner jedisSummoner = (JedisPooledSummoner) summoner;
|
|
||||||
return this.unifiedJedisTask(jedisSummoner.obtainResource());
|
|
||||||
} else if (api.getMode() == RedisBungeeMode.CLUSTER) {
|
|
||||||
JedisClusterSummoner jedisClusterSummoner = (JedisClusterSummoner) summoner;
|
|
||||||
return this.unifiedJedisTask(jedisClusterSummoner.obtainResource());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RedisBungeePlugin<?> getPlugin() {
|
|
||||||
if (plugin == null) {
|
|
||||||
throw new NullPointerException("Plugin is null in the task");
|
|
||||||
}
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.tasks;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisCluster;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ShutdownUtils {
|
|
||||||
|
|
||||||
public static void shutdownCleanup(RedisBungeePlugin<?> plugin) {
|
|
||||||
new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
unifiedJedis.hdel("heartbeats", plugin.getConfiguration().getProxyId());
|
|
||||||
if (unifiedJedis.scard("proxy:" + plugin.getConfiguration().getProxyId() + ":usersOnline") > 0) {
|
|
||||||
Set<String> players = unifiedJedis.smembers("proxy:" + plugin.getConfiguration().getProxyId() + ":usersOnline");
|
|
||||||
for (String member : players)
|
|
||||||
PlayerUtils.cleanUpPlayer(member, unifiedJedis, true);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee.api.util;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public class RedisUtil {
|
|
||||||
public final static int PROXY_TIMEOUT = 30;
|
|
||||||
public static boolean isRedisVersionRight(String redisVersion) {
|
|
||||||
String[] args = redisVersion.split("\\.");
|
|
||||||
if (args.length < 2) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int major = Integer.parseInt(args[0]);
|
|
||||||
int minor = Integer.parseInt(args[1]);
|
|
||||||
return major >= 3 && minor >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ham1255: i am keeping this if some plugin uses this *IF*
|
|
||||||
@Deprecated
|
|
||||||
public static boolean canUseLua(String redisVersion) {
|
|
||||||
// Need to use >=3 to use Lua optimizations.
|
|
||||||
return isRedisVersionRight(redisVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee.api.util.io;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
|
|
||||||
public class IOUtil {
|
|
||||||
public static String readInputStreamAsString(InputStream is) {
|
|
||||||
String string;
|
|
||||||
try {
|
|
||||||
string = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee.api.util.payload;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class PayloadUtils {
|
|
||||||
private static final Gson gson = new Gson();
|
|
||||||
|
|
||||||
public static void playerJoinPayload(UUID uuid, UnifiedJedis unifiedJedis, InetAddress inetAddress) {
|
|
||||||
unifiedJedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
|
||||||
uuid, AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
|
|
||||||
new AbstractDataManager.LoginPayload(inetAddress))));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void playerQuitPayload(String uuid, UnifiedJedis unifiedJedis, long timestamp) {
|
|
||||||
unifiedJedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
|
||||||
UUID.fromString(uuid), AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
|
||||||
new AbstractDataManager.LogoutPayload(timestamp))));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void playerServerChangePayload(UUID uuid, UnifiedJedis unifiedJedis, String newServer, String oldServer) {
|
|
||||||
unifiedJedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
|
||||||
uuid, AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
|
||||||
new AbstractDataManager.ServerChangePayload(newServer, oldServer))));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void kickPlayerPayload(UUID uuid, String message, UnifiedJedis unifiedJedis) {
|
|
||||||
unifiedJedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
|
||||||
uuid, AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId(), AbstractDataManager.DataManagerMessage.Action.KICK,
|
|
||||||
new AbstractDataManager.KickPayload(message))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee.api.util.player;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
|
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerQuitPayload;
|
|
||||||
|
|
||||||
public class PlayerUtils {
|
|
||||||
|
|
||||||
public static void cleanUpPlayer(String uuid, UnifiedJedis rsc, boolean firePayload) {
|
|
||||||
final long timestamp = System.currentTimeMillis();
|
|
||||||
final boolean isKickedFromOtherLocation = isKickedOtherLocation(uuid, rsc);
|
|
||||||
rsc.srem("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", uuid);
|
|
||||||
if (!isKickedFromOtherLocation) {
|
|
||||||
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
|
|
||||||
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
|
|
||||||
}
|
|
||||||
if (firePayload && !isKickedFromOtherLocation) {
|
|
||||||
playerQuitPayload(uuid, rsc, timestamp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setKickedOtherLocation(String uuid, UnifiedJedis unifiedJedis) {
|
|
||||||
// set anything for sake of exists check. then expire it after 2 seconds. should be great?
|
|
||||||
unifiedJedis.set("kicked-other-location::" + uuid, "0");
|
|
||||||
unifiedJedis.expire("kicked-other-location::" + uuid, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isKickedOtherLocation(String uuid, UnifiedJedis unifiedJedis) {
|
|
||||||
return unifiedJedis.exists("kicked-other-location::" + uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void createPlayer(UUID uuid, UnifiedJedis unifiedJedis, String currentServer, InetAddress hostname, boolean fireEvent) {
|
|
||||||
final boolean isKickedFromOtherLocation = isKickedOtherLocation(uuid.toString(), unifiedJedis);
|
|
||||||
Map<String, String> playerData = new HashMap<>(4);
|
|
||||||
playerData.put("online", "0");
|
|
||||||
playerData.put("ip", hostname.getHostName());
|
|
||||||
playerData.put("proxy", AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId());
|
|
||||||
if (currentServer != null) {
|
|
||||||
playerData.put("server", currentServer);
|
|
||||||
}
|
|
||||||
unifiedJedis.sadd("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", uuid.toString());
|
|
||||||
unifiedJedis.hset("player:" + uuid, playerData);
|
|
||||||
if (fireEvent && !isKickedFromOtherLocation) {
|
|
||||||
playerJoinPayload(uuid, unifiedJedis, hostname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee.api.util.serialize;
|
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.common.collect.Multiset;
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Serializations {
|
|
||||||
|
|
||||||
public static void serializeMultiset(Multiset<String> collection, ByteArrayDataOutput output) {
|
|
||||||
output.writeInt(collection.elementSet().size());
|
|
||||||
for (Multiset.Entry<String> entry : collection.entrySet()) {
|
|
||||||
output.writeUTF(entry.getElement());
|
|
||||||
output.writeInt(entry.getCount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("SameParameterValue")
|
|
||||||
public static void serializeMultimap(Multimap<String, String> collection, boolean includeNames, ByteArrayDataOutput output) {
|
|
||||||
output.writeInt(collection.keySet().size());
|
|
||||||
for (Map.Entry<String, Collection<String>> entry : collection.asMap().entrySet()) {
|
|
||||||
output.writeUTF(entry.getKey());
|
|
||||||
if (includeNames) {
|
|
||||||
serializeCollection(entry.getValue(), output);
|
|
||||||
} else {
|
|
||||||
output.writeInt(entry.getValue().size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void serializeCollection(Collection<?> collection, ByteArrayDataOutput output) {
|
|
||||||
output.writeInt(collection.size());
|
|
||||||
for (Object o : collection) {
|
|
||||||
output.writeUTF(o.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class CachedUUIDEntry {
|
|
||||||
private final String name;
|
|
||||||
private final UUID uuid;
|
|
||||||
private final Calendar expiry;
|
|
||||||
|
|
||||||
public CachedUUIDEntry(String name, UUID uuid, Calendar expiry) {
|
|
||||||
this.name = name;
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.expiry = expiry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Calendar getExpiry() {
|
|
||||||
return expiry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean expired() {
|
|
||||||
return Calendar.getInstance().after(expiry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
|
||||||
import com.squareup.okhttp.Request;
|
|
||||||
import com.squareup.okhttp.ResponseBody;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class NameFetcher {
|
|
||||||
private static OkHttpClient httpClient;
|
|
||||||
private static final Gson gson = new Gson();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void setHttpClient(OkHttpClient httpClient) {
|
|
||||||
throw new UnsupportedOperationException("Due mojang disabled the Names API NameFetcher no longer functions and has been disabled");
|
|
||||||
// NameFetcher.httpClient = httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
|
|
||||||
throw new UnsupportedOperationException("Due mojang disabled the Names API NameFetcher no longer functions and has been disabled");
|
|
||||||
// String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names";
|
|
||||||
// Request request = new Request.Builder().url(url).get().build();
|
|
||||||
// ResponseBody body = httpClient.newCall(request).execute().body();
|
|
||||||
// String response = body.string();
|
|
||||||
// body.close();
|
|
||||||
//
|
|
||||||
// Type listType = new TypeToken<List<Name>>() {
|
|
||||||
// }.getType();
|
|
||||||
// List<Name> names = gson.fromJson(response, listType);
|
|
||||||
//
|
|
||||||
// List<String> humanNames = new ArrayList<>();
|
|
||||||
// for (Name name : names) {
|
|
||||||
// humanNames.add(name.name);
|
|
||||||
// }
|
|
||||||
// return humanNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static class Name {
|
|
||||||
private String name;
|
|
||||||
private long changedToAt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.squareup.okhttp.*;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
/* Credits to evilmidget38 for this class. I modified it to use Gson. */
|
|
||||||
public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
|
||||||
private static final double PROFILES_PER_REQUEST = 100;
|
|
||||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
|
||||||
private static final MediaType JSON = MediaType.parse("application/json");
|
|
||||||
private final List<String> names;
|
|
||||||
private final boolean rateLimiting;
|
|
||||||
private static final Gson gson = new Gson();
|
|
||||||
|
|
||||||
|
|
||||||
public static void setHttpClient(OkHttpClient httpClient) {
|
|
||||||
UUIDFetcher.httpClient = httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OkHttpClient httpClient;
|
|
||||||
|
|
||||||
private UUIDFetcher(List<String> names, boolean rateLimiting) {
|
|
||||||
this.names = ImmutableList.copyOf(names);
|
|
||||||
this.rateLimiting = rateLimiting;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUIDFetcher(List<String> names) {
|
|
||||||
this(names, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UUID getUUID(String id) {
|
|
||||||
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, UUID> call() throws Exception {
|
|
||||||
Map<String, UUID> uuidMap = new HashMap<>();
|
|
||||||
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
|
||||||
for (int i = 0; i < requests; i++) {
|
|
||||||
String body = gson.toJson(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
|
||||||
Request request = new Request.Builder().url(PROFILE_URL).post(RequestBody.create(JSON, body)).build();
|
|
||||||
ResponseBody responseBody = httpClient.newCall(request).execute().body();
|
|
||||||
String response = responseBody.string();
|
|
||||||
responseBody.close();
|
|
||||||
Profile[] array = gson.fromJson(response, Profile[].class);
|
|
||||||
for (Profile profile : array) {
|
|
||||||
UUID uuid = UUIDFetcher.getUUID(profile.id);
|
|
||||||
uuidMap.put(profile.name, uuid);
|
|
||||||
}
|
|
||||||
if (rateLimiting && i != requests - 1) {
|
|
||||||
Thread.sleep(100L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uuidMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Profile {
|
|
||||||
String id;
|
|
||||||
String name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,212 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
import redis.clients.jedis.exceptions.JedisException;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public final class UUIDTranslator {
|
|
||||||
private static final Pattern UUID_PATTERN = Pattern.compile("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}");
|
|
||||||
private static final Pattern MOJANGIAN_UUID_PATTERN = Pattern.compile("[a-fA-F0-9]{32}");
|
|
||||||
private final RedisBungeePlugin<?> plugin;
|
|
||||||
private final Map<String, CachedUUIDEntry> nameToUuidMap = new ConcurrentHashMap<>(128, 0.5f, 4);
|
|
||||||
private final Map<UUID, CachedUUIDEntry> uuidToNameMap = new ConcurrentHashMap<>(128, 0.5f, 4);
|
|
||||||
private static final Gson gson = new Gson();
|
|
||||||
|
|
||||||
public UUIDTranslator(RedisBungeePlugin<?> plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addToMaps(String name, UUID uuid) {
|
|
||||||
// This is why I like LocalDate...
|
|
||||||
|
|
||||||
// Cache the entry for three days.
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, 3);
|
|
||||||
|
|
||||||
// Create the entry and populate the local maps
|
|
||||||
CachedUUIDEntry entry = new CachedUUIDEntry(name, uuid, calendar);
|
|
||||||
nameToUuidMap.put(name.toLowerCase(), entry);
|
|
||||||
uuidToNameMap.put(uuid, entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getTranslatedUuid(@NonNull String player, boolean expensiveLookups) {
|
|
||||||
// If the player is online, give them their UUID.
|
|
||||||
// Remember, local data > remote data.
|
|
||||||
if (plugin.getPlayer(player) != null)
|
|
||||||
return plugin.getPlayerUUID(player);
|
|
||||||
|
|
||||||
// Check if it exists in the map
|
|
||||||
CachedUUIDEntry cachedUUIDEntry = nameToUuidMap.get(player.toLowerCase());
|
|
||||||
if (cachedUUIDEntry != null) {
|
|
||||||
if (!cachedUUIDEntry.expired())
|
|
||||||
return cachedUUIDEntry.getUuid();
|
|
||||||
else
|
|
||||||
nameToUuidMap.remove(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we can exit early
|
|
||||||
if (UUID_PATTERN.matcher(player).find()) {
|
|
||||||
return UUID.fromString(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MOJANGIAN_UUID_PATTERN.matcher(player).find()) {
|
|
||||||
// Reconstruct the UUID
|
|
||||||
return UUIDFetcher.getUUID(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we are in offline mode, UUID generation is simple.
|
|
||||||
// We don't even have to cache the UUID, since this is easy to recalculate.
|
|
||||||
if (!plugin.isOnlineMode()) {
|
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player).getBytes(Charsets.UTF_8));
|
|
||||||
}
|
|
||||||
RedisTask<UUID> redisTask = new RedisTask<UUID>(plugin) {
|
|
||||||
@Override
|
|
||||||
public UUID unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
String stored = unifiedJedis.hget("uuid-cache", player.toLowerCase());
|
|
||||||
if (stored != null) {
|
|
||||||
// Found an entry value. Deserialize it.
|
|
||||||
CachedUUIDEntry entry = gson.fromJson(stored, CachedUUIDEntry.class);
|
|
||||||
|
|
||||||
// Check for expiry:
|
|
||||||
if (entry.expired()) {
|
|
||||||
unifiedJedis.hdel("uuid-cache", player.toLowerCase());
|
|
||||||
// Doesn't hurt to also remove the UUID entry as well.
|
|
||||||
unifiedJedis.hdel("uuid-cache", entry.getUuid().toString());
|
|
||||||
} else {
|
|
||||||
nameToUuidMap.put(player.toLowerCase(), entry);
|
|
||||||
uuidToNameMap.put(entry.getUuid(), entry);
|
|
||||||
return entry.getUuid();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// That didn't work. Let's ask Mojang.
|
|
||||||
if (!expensiveLookups || !plugin.isOnlineMode())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
Map<String, UUID> uuidMap1;
|
|
||||||
try {
|
|
||||||
uuidMap1 = new UUIDFetcher(Collections.singletonList(player)).call();
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.logFatal("Unable to fetch UUID from Mojang for " + player);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, UUID> entry : uuidMap1.entrySet()) {
|
|
||||||
if (entry.getKey().equalsIgnoreCase(player)) {
|
|
||||||
persistInfo(entry.getKey(), entry.getValue(), unifiedJedis);
|
|
||||||
return entry.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Let's try Redis.
|
|
||||||
try {
|
|
||||||
return redisTask.execute();
|
|
||||||
} catch (JedisException e) {
|
|
||||||
plugin.logFatal("Unable to fetch UUID for " + player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null; // Nope, game over!
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNameFromUuid(@NonNull UUID player, boolean expensiveLookups) {
|
|
||||||
// If the player is online, give them their UUID.
|
|
||||||
// Remember, local data > remote data.
|
|
||||||
if (plugin.getPlayer(player) != null)
|
|
||||||
return plugin.getPlayerName(player);
|
|
||||||
|
|
||||||
// Check if it exists in the map
|
|
||||||
CachedUUIDEntry cachedUUIDEntry = uuidToNameMap.get(player);
|
|
||||||
if (cachedUUIDEntry != null) {
|
|
||||||
if (!cachedUUIDEntry.expired())
|
|
||||||
return cachedUUIDEntry.getName();
|
|
||||||
else
|
|
||||||
uuidToNameMap.remove(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
RedisTask<String> redisTask = new RedisTask<String>(plugin) {
|
|
||||||
@Override
|
|
||||||
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
String stored = unifiedJedis.hget("uuid-cache", player.toString());
|
|
||||||
if (stored != null) {
|
|
||||||
// Found an entry value. Deserialize it.
|
|
||||||
CachedUUIDEntry entry = gson.fromJson(stored, CachedUUIDEntry.class);
|
|
||||||
|
|
||||||
// Check for expiry:
|
|
||||||
if (entry.expired()) {
|
|
||||||
unifiedJedis.hdel("uuid-cache", player.toString());
|
|
||||||
// Doesn't hurt to also remove the named entry as well.
|
|
||||||
// TODO: Since UUIDs are fixed, we could look up the name and see if the UUID matches.
|
|
||||||
unifiedJedis.hdel("uuid-cache", entry.getName());
|
|
||||||
} else {
|
|
||||||
nameToUuidMap.put(entry.getName().toLowerCase(), entry);
|
|
||||||
uuidToNameMap.put(player, entry);
|
|
||||||
return entry.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!expensiveLookups || !plugin.isOnlineMode())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// That didn't work. Let's ask Mojang. This call may fail, because Mojang is insane.
|
|
||||||
//
|
|
||||||
// UPDATE: Mojang has removed the API somewhere in september/2022 due privacy issues
|
|
||||||
// this is expected to fail now, so we will keep logging it until we figure out something or remove name fetching completely
|
|
||||||
// Name fetching class was deprecated as result
|
|
||||||
String name;
|
|
||||||
try {
|
|
||||||
plugin.logFatal("Due Mojang removing the naming API, we were unable to fetch player names.");
|
|
||||||
name = Iterables.getLast(NameFetcher.nameHistoryFromUuid(player));
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.logFatal("Unable to fetch name from Mojang for " + player);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name != null) {
|
|
||||||
persistInfo(name, player, unifiedJedis);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Okay, it wasn't locally cached. Let's try Redis.
|
|
||||||
try {
|
|
||||||
return redisTask.execute();
|
|
||||||
} catch (JedisException e) {
|
|
||||||
plugin.logFatal("Unable to fetch name for " + player);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void persistInfo(String name, UUID uuid, UnifiedJedis unifiedJedis) {
|
|
||||||
addToMaps(name, uuid);
|
|
||||||
String json = gson.toJson(uuidToNameMap.get(uuid));
|
|
||||||
unifiedJedis.hset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
# RedisBungee configuration file.
|
|
||||||
|
|
||||||
# Cluster Mode
|
|
||||||
# enabling this option will enable cluster mode.
|
|
||||||
cluster-mode-enabled: false
|
|
||||||
|
|
||||||
# FORMAT:
|
|
||||||
# redis-cluster-servers:
|
|
||||||
# - host: 127.0.0.1
|
|
||||||
# port: 2020
|
|
||||||
# - host: 127.0.0.1
|
|
||||||
# port: 2021
|
|
||||||
# - host: 127.0.0.1
|
|
||||||
# port: 2021
|
|
||||||
|
|
||||||
# you can set single server and Jedis will automatically discover cluster nodes,
|
|
||||||
# but might fail if this single redis node is down when Proxy startup, its recommended put the all the nodes
|
|
||||||
redis-cluster-servers:
|
|
||||||
- host: 127.0.0.1
|
|
||||||
port: 6379
|
|
||||||
|
|
||||||
# Get Redis from http://redis.io/
|
|
||||||
# The Redis server you use.
|
|
||||||
# these settings are ignored when cluster mode is enabled.
|
|
||||||
redis-server: 127.0.0.1
|
|
||||||
redis-port: 6379
|
|
||||||
|
|
||||||
# OPTIONAL but recommended: If your Redis server uses AUTH, set the password required.
|
|
||||||
redis-password: ""
|
|
||||||
# Maximum connections that will be maintained to the Redis server.
|
|
||||||
# The default is 10. This setting should be left as-is unless you have some wildly
|
|
||||||
# inefficient plugins or a lot of players.
|
|
||||||
max-redis-connections: 10
|
|
||||||
|
|
||||||
# since redis can support ssl by version 6 you can use ssl / tls in redis bungee too!
|
|
||||||
# but there is more configuration needed to work see https://github.com/ProxioDev/RedisBungee/issues/18
|
|
||||||
# Keep note that SSL/TLS connections will decrease redis performance so use it when needed.
|
|
||||||
useSSL: false
|
|
||||||
|
|
||||||
# An identifier for this BungeeCord / Velocity instance. Will randomly generate if leaving it blank.
|
|
||||||
proxy-id: "test-1"
|
|
||||||
|
|
||||||
# since version 0.8.0 Internally now uses JedisPooled instead of Jedis, JedisPool.
|
|
||||||
# which will break compatibility with old plugins that uses RedisBungee JedisPool
|
|
||||||
# so to mitigate this issue, we will instruct RedisBungee to init an JedisPool for compatibility reasons.
|
|
||||||
# enabled by default
|
|
||||||
# ignored when cluster mode is enabled
|
|
||||||
enable-jedis-pool-compatibility: true
|
|
||||||
# max connections for the compatibility pool
|
|
||||||
compatibility-max-connections: 3
|
|
||||||
|
|
||||||
# Register redis bungee legacy commands
|
|
||||||
# if this disabled override-bungee-commands will be ignored
|
|
||||||
register-legacy-commands: false
|
|
||||||
|
|
||||||
# Whether or not RedisBungee should install its version of regular BungeeCord commands.
|
|
||||||
# Often, the RedisBungee commands are desired, but in some cases someone may wish to
|
|
||||||
# override the commands using another plugin.
|
|
||||||
#
|
|
||||||
# If you are just denying access to the commands, RedisBungee uses the default BungeeCord
|
|
||||||
# permissions - just deny them and access will be denied.
|
|
||||||
#
|
|
||||||
# Please note that with build 787+, most commands overridden by RedisBungee were moved to
|
|
||||||
# modules, and these must be disabled or overridden yourself.
|
|
||||||
override-bungee-commands: false
|
|
||||||
|
|
||||||
# A list of IP addresses for which RedisBungee will not modify the response for, useful for automatic
|
|
||||||
# restart scripts.
|
|
||||||
exempt-ip-addresses: []
|
|
||||||
|
|
||||||
# restore old login when online behavior before 0.9.0 update
|
|
||||||
# uncomment to enable it
|
|
||||||
|
|
||||||
# disable-kick-when-online: true
|
|
||||||
|
|
||||||
# Config version DO NOT CHANGE!!!!
|
|
||||||
config-version: 1
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
logged-in-other-location: "§cYou logged in from another location!"
|
|
||||||
already-logged-in: "§cYou are already logged in!"
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>RedisBungee</artifactId>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<version>0.10.2-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>RedisBungee-Bungee</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>bungeecord-repo</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<version>3.3.2</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-javadocs</id>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
<includeDependencySources>true</includeDependencySources>
|
|
||||||
<dependencySourceExcludes>
|
|
||||||
<dependencySourceExclude>net.md-5:*</dependencySourceExclude>
|
|
||||||
</dependencySourceExcludes>
|
|
||||||
<destDir>../javadoc/${project.name}</destDir>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.2.4</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>redis.clients.jedis</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>redis.clients.util</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.apache.commons.pool</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.squareup.okhttp</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okhttp
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>okio</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okio</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.google</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.google
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.json</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.json</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.checkerframework</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.checkframework
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>ninja.leaping.configurate</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.configurate
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<artifactId>RedisBungee-API</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<artifactId>RedisBungee-API</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<classifier>javadoc</classifier>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
<artifactId>bungeecord-api</artifactId>
|
|
||||||
<version>1.17-R0.1-SNAPSHOT</version>
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BungeeDataManager extends AbstractDataManager<ProxiedPlayer, PostLoginEvent, PlayerDisconnectEvent, PubSubMessageEvent> implements Listener {
|
|
||||||
|
|
||||||
public BungeeDataManager(RedisBungeePlugin<ProxiedPlayer> plugin) {
|
|
||||||
super(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler
|
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
|
||||||
invalidate(event.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerDisconnect(PlayerDisconnectEvent event) {
|
|
||||||
invalidate(event.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler
|
|
||||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
|
||||||
handlePubSubMessage(event.getChannel(), event.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handleKick(UUID target, String message) {
|
|
||||||
// check if the player is online on this proxy
|
|
||||||
ProxiedPlayer player = plugin.getPlayer(target);
|
|
||||||
if (player == null) return false;
|
|
||||||
player.disconnect(TextComponent.fromLegacyText(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
public class BungeePlayerUtils {
|
|
||||||
|
|
||||||
public static void createBungeePlayer(ProxiedPlayer player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
|
||||||
String serverName = null;
|
|
||||||
if (player.getServer() != null) {
|
|
||||||
serverName = player.getServer().getInfo().getName();
|
|
||||||
}
|
|
||||||
PendingConnection pendingConnection = player.getPendingConnection();
|
|
||||||
PlayerUtils.createPlayer(player.getUniqueId(), unifiedJedis, serverName, pendingConnection.getAddress().getAddress(), fireEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,362 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.config.ConfigLoader;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.*;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.commands.RedisBungeeCommands;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.*;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.NameFetcher;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDFetcher;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator;
|
|
||||||
import com.squareup.okhttp.Dispatcher;
|
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
|
||||||
import redis.clients.jedis.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
|
|
||||||
public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlayer>, ConfigLoader {
|
|
||||||
|
|
||||||
private static RedisBungeeAPI apiStatic;
|
|
||||||
|
|
||||||
private AbstractRedisBungeeAPI api;
|
|
||||||
private RedisBungeeMode redisBungeeMode;
|
|
||||||
private PubSubListener psl = null;
|
|
||||||
private Summoner<?> summoner;
|
|
||||||
private UUIDTranslator uuidTranslator;
|
|
||||||
private RedisBungeeConfiguration configuration;
|
|
||||||
private BungeeDataManager dataManager;
|
|
||||||
private OkHttpClient httpClient;
|
|
||||||
private volatile List<String> proxiesIds;
|
|
||||||
private final AtomicInteger globalPlayerCount = new AtomicInteger();
|
|
||||||
private Future<?> integrityCheck;
|
|
||||||
private Future<?> heartbeatTask;
|
|
||||||
private static final Object SERVER_TO_PLAYERS_KEY = new Object();
|
|
||||||
private final Cache<Object, Multimap<String, UUID>> serverToPlayersCache = CacheBuilder.newBuilder()
|
|
||||||
.expireAfterWrite(5, TimeUnit.SECONDS)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RedisBungeeConfiguration getConfiguration() {
|
|
||||||
return this.configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return this.globalPlayerCount.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getLocalPlayersAsUuidStrings() {
|
|
||||||
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
|
|
||||||
for (ProxiedPlayer player : getProxy().getPlayers()) {
|
|
||||||
builder.add(player.getUniqueId().toString());
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AbstractDataManager<ProxiedPlayer, ?, ?, ?> getDataManager() {
|
|
||||||
return this.dataManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AbstractRedisBungeeAPI getAbstractRedisBungeeApi() {
|
|
||||||
return this.api;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUIDTranslator getUuidTranslator() {
|
|
||||||
return this.uuidTranslator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Multimap<String, UUID> serverToPlayersCache() {
|
|
||||||
try {
|
|
||||||
return this.serverToPlayersCache.get(SERVER_TO_PLAYERS_KEY, this::serversToPlayers);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getProxiesIds() {
|
|
||||||
return proxiesIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PubSubListener getPubSubListener() {
|
|
||||||
return this.psl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeAsync(Runnable runnable) {
|
|
||||||
this.getProxy().getScheduler().runAsync(this, runnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeAsyncAfter(Runnable runnable, TimeUnit timeUnit, int time) {
|
|
||||||
this.getProxy().getScheduler().schedule(this, runnable, time, timeUnit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fireEvent(Object event) {
|
|
||||||
this.getProxy().getPluginManager().callEvent((Event) event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOnlineMode() {
|
|
||||||
return this.getProxy().getConfig().isOnlineMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logInfo(String msg) {
|
|
||||||
this.getLogger().info(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logWarn(String msg) {
|
|
||||||
this.getLogger().warning(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logFatal(String msg) {
|
|
||||||
this.getLogger().severe(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProxiedPlayer getPlayer(UUID uuid) {
|
|
||||||
return this.getProxy().getPlayer(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProxiedPlayer getPlayer(String name) {
|
|
||||||
return this.getProxy().getPlayer(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getPlayerUUID(String player) {
|
|
||||||
return this.getProxy().getPlayer(player).getUniqueId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPlayerName(UUID player) {
|
|
||||||
return this.getProxy().getPlayer(player).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPlayerServerName(ProxiedPlayer player) {
|
|
||||||
return player.getServer().getInfo().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPlayerOnAServer(ProxiedPlayer player) {
|
|
||||||
return player.getServer() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InetAddress getPlayerIp(ProxiedPlayer player) {
|
|
||||||
return player.getAddress().getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize() {
|
|
||||||
ThreadFactory factory = ((ThreadPoolExecutor) getExecutorService()).getThreadFactory();
|
|
||||||
ScheduledExecutorService service = Executors.newScheduledThreadPool(24, factory);
|
|
||||||
try {
|
|
||||||
Field field = Plugin.class.getDeclaredField("service");
|
|
||||||
field.setAccessible(true);
|
|
||||||
ExecutorService builtinService = (ExecutorService) field.get(this);
|
|
||||||
field.set(this, service);
|
|
||||||
builtinService.shutdownNow();
|
|
||||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
||||||
getLogger().log(Level.WARNING, "Can't replace BungeeCord thread pool with our own");
|
|
||||||
getLogger().log(Level.INFO, "skipping replacement.....");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
loadConfig(this, getDataFolder());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Unable to load/save config", e);
|
|
||||||
}
|
|
||||||
// init the api class
|
|
||||||
this.api = new RedisBungeeAPI(this);
|
|
||||||
apiStatic = (RedisBungeeAPI) this.api;
|
|
||||||
// init the http lib
|
|
||||||
httpClient = new OkHttpClient();
|
|
||||||
Dispatcher dispatcher = new Dispatcher(getExecutorService());
|
|
||||||
httpClient.setDispatcher(dispatcher);
|
|
||||||
//NameFetcher.setHttpClient(httpClient);
|
|
||||||
UUIDFetcher.setHttpClient(httpClient);
|
|
||||||
InitialUtils.checkRedisVersion(this);
|
|
||||||
// check if this proxy is recovering from a crash and start heart the beat.
|
|
||||||
InitialUtils.checkIfRecovering(this, getDataFolder().toPath());
|
|
||||||
updateProxiesIds();
|
|
||||||
uuidTranslator = new UUIDTranslator(this);
|
|
||||||
heartbeatTask = service.scheduleAtFixedRate(new HeartbeatTask(this, this.globalPlayerCount), 0, HeartbeatTask.INTERVAL, HeartbeatTask.REPEAT_INTERVAL_TIME_UNIT);
|
|
||||||
dataManager = new BungeeDataManager(this);
|
|
||||||
getProxy().getPluginManager().registerListener(this, new RedisBungeeBungeeListener(this, configuration.getExemptAddresses()));
|
|
||||||
getProxy().getPluginManager().registerListener(this, dataManager);
|
|
||||||
psl = new PubSubListener(this);
|
|
||||||
getProxy().getScheduler().runAsync(this, psl);
|
|
||||||
|
|
||||||
IntegrityCheckTask integrityCheckTask = new IntegrityCheckTask(this) {
|
|
||||||
@Override
|
|
||||||
public void handlePlatformPlayer(String player, UnifiedJedis unifiedJedis) {
|
|
||||||
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(UUID.fromString(player));
|
|
||||||
if (proxiedPlayer == null)
|
|
||||||
return; // We'll deal with it later.
|
|
||||||
|
|
||||||
BungeePlayerUtils.createBungeePlayer(proxiedPlayer, unifiedJedis, false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
integrityCheck = service.scheduleAtFixedRate(integrityCheckTask::execute, 0, IntegrityCheckTask.INTERVAL, IntegrityCheckTask.TIMEUNIT);
|
|
||||||
|
|
||||||
// register plugin messages channel.
|
|
||||||
getProxy().registerChannel("legacy:redisbungee");
|
|
||||||
getProxy().registerChannel("RedisBungee");
|
|
||||||
if (configuration.doRegisterLegacyCommands()) {
|
|
||||||
// register commands
|
|
||||||
if (configuration.doOverrideBungeeCommands()) {
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand(this));
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.FindCommand(this));
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.LastSeenCommand(this));
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.IpCommand(this));
|
|
||||||
}
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.SendToAll(this));
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.ServerId(this));
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.ServerIds(this));
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlayerProxyCommand(this));
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlistCommand(this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
// Poison the PubSub listener
|
|
||||||
if (psl != null) {
|
|
||||||
psl.poison();
|
|
||||||
}
|
|
||||||
if (integrityCheck != null) {
|
|
||||||
integrityCheck.cancel(true);
|
|
||||||
}
|
|
||||||
if (heartbeatTask != null) {
|
|
||||||
heartbeatTask.cancel(true);
|
|
||||||
}
|
|
||||||
getProxy().getPluginManager().unregisterListeners(this);
|
|
||||||
ShutdownUtils.shutdownCleanup(this);
|
|
||||||
try {
|
|
||||||
this.summoner.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Summoner<?> getSummoner() {
|
|
||||||
return this.summoner;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RedisBungeeMode getRedisBungeeMode() {
|
|
||||||
return this.redisBungeeMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateProxiesIds() {
|
|
||||||
proxiesIds = getCurrentProxiesIds(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPlayerChangedServerNetworkEvent createPlayerChangedServerNetworkEvent(UUID uuid, String previousServer, String server) {
|
|
||||||
return new PlayerChangedServerNetworkEvent(uuid, previousServer, server);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPlayerJoinedNetworkEvent createPlayerJoinedNetworkEvent(UUID uuid) {
|
|
||||||
return new PlayerJoinedNetworkEvent(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPlayerLeftNetworkEvent createPlayerLeftNetworkEvent(UUID uuid) {
|
|
||||||
return new PlayerLeftNetworkEvent(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPubSubMessageEvent createPubSubEvent(String channel, String message) {
|
|
||||||
return new PubSubMessageEvent(channel, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfigLoad(RedisBungeeConfiguration configuration, Summoner<?> summoner, RedisBungeeMode mode) {
|
|
||||||
this.configuration = configuration;
|
|
||||||
this.redisBungeeMode = mode;
|
|
||||||
this.summoner = summoner;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns an instance of {@link RedisBungeeAPI}
|
|
||||||
*
|
|
||||||
* @deprecated Please use {@link RedisBungeeAPI#getRedisBungeeApi()} this class intended to for old plugins that no longer updated.
|
|
||||||
*
|
|
||||||
* @return the {@link AbstractRedisBungeeAPI} object instance.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static RedisBungeeAPI getApi() {
|
|
||||||
return apiStatic;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public JedisPool getPool() {
|
|
||||||
return api.getJedisPool();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This platform class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungeeAPI#getRedisBungeeApi()}
|
|
||||||
* or somehow you got the Plugin instance by you can call the api using {@link RedisBungeePlugin#getAbstractRedisBungeeApi()}.
|
|
||||||
*
|
|
||||||
* @author tuxed
|
|
||||||
* @since 0.2.3 | updated 0.8.0
|
|
||||||
*/
|
|
||||||
public class RedisBungeeAPI extends AbstractRedisBungeeAPI {
|
|
||||||
|
|
||||||
private static RedisBungeeAPI redisBungeeApi;
|
|
||||||
|
|
||||||
public RedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
|
||||||
super(plugin);
|
|
||||||
if (redisBungeeApi == null) {
|
|
||||||
redisBungeeApi = this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the server where the specified player is playing. This function also deals with the case of local players
|
|
||||||
* as well, and will return local information on them.
|
|
||||||
*
|
|
||||||
* @param player a player uuid
|
|
||||||
* @return {@link ServerInfo} Can be null if proxy can't find it.
|
|
||||||
* @see #getServerNameFor(UUID)
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public final ServerInfo getServerFor(@NonNull UUID player) {
|
|
||||||
String serverName = this.getServerNameFor(player);
|
|
||||||
if (serverName == null) return null;
|
|
||||||
return ((Plugin) this.plugin).getProxy().getServerInfo(serverName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Api instance
|
|
||||||
*
|
|
||||||
* @return the API instance.
|
|
||||||
* @since 0.6.5
|
|
||||||
*/
|
|
||||||
public static RedisBungeeAPI getRedisBungeeApi() {
|
|
||||||
return redisBungeeApi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,252 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.collect.HashMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractRedisBungeeListener;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
|
||||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.connection.Server;
|
|
||||||
import net.md_5.bungee.api.event.*;
|
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.Serializations.serializeMultimap;
|
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.Serializations.serializeMultiset;
|
|
||||||
import static net.md_5.bungee.event.EventPriority.HIGHEST;
|
|
||||||
|
|
||||||
public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<LoginEvent, PostLoginEvent, PlayerDisconnectEvent, ServerConnectedEvent, ProxyPingEvent, PluginMessageEvent, PubSubMessageEvent> implements Listener {
|
|
||||||
|
|
||||||
|
|
||||||
public RedisBungeeBungeeListener(RedisBungeePlugin<?> plugin, List<InetAddress> exemptAddresses) {
|
|
||||||
super(plugin, exemptAddresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler(priority = HIGHEST)
|
|
||||||
public void onLogin(LoginEvent event) {
|
|
||||||
event.registerIntent((Plugin) plugin);
|
|
||||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
try {
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (plugin.getConfiguration().restoreOldKickBehavior()) {
|
|
||||||
for (String s : plugin.getProxiesIds()) {
|
|
||||||
if (unifiedJedis.sismember("proxy:" + s + ":usersOnline", event.getConnection().getUniqueId().toString())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
event.setCancelReason(plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (api.isPlayerOnline(event.getConnection().getUniqueId())) {
|
|
||||||
PlayerUtils.setKickedOtherLocation(event.getConnection().getUniqueId().toString(), unifiedJedis);
|
|
||||||
api.kickPlayer(event.getConnection().getUniqueId(), plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
event.completeIntent((Plugin) plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler
|
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
|
||||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), unifiedJedis);
|
|
||||||
BungeePlayerUtils.createBungeePlayer(event.getPlayer(), unifiedJedis, true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerDisconnect(PlayerDisconnectEvent event) {
|
|
||||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
PlayerUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), unifiedJedis, true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler
|
|
||||||
public void onServerChange(ServerConnectedEvent event) {
|
|
||||||
final String currentServer = event.getServer().getInfo().getName();
|
|
||||||
final String oldServer = event.getPlayer().getServer() == null ? null : event.getPlayer().getServer().getInfo().getName();
|
|
||||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
unifiedJedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
|
||||||
PayloadUtils.playerServerChangePayload(event.getPlayer().getUniqueId(), unifiedJedis, currentServer, oldServer);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler
|
|
||||||
public void onPing(ProxyPingEvent event) {
|
|
||||||
if (exemptAddresses.contains(event.getConnection().getAddress().getAddress())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ServerInfo forced = AbstractReconnectHandler.getForcedHost(event.getConnection());
|
|
||||||
|
|
||||||
if (forced != null && event.getConnection().getListener().isPingPassthrough()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.getResponse().getPlayers().setOnline(plugin.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
|
||||||
if ((event.getTag().equals("legacy:redisbungee") || event.getTag().equals("RedisBungee")) && event.getSender() instanceof Server) {
|
|
||||||
final String currentChannel = event.getTag();
|
|
||||||
final byte[] data = Arrays.copyOf(event.getData(), event.getData().length);
|
|
||||||
plugin.executeAsync(() -> {
|
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(data);
|
|
||||||
|
|
||||||
String subchannel = in.readUTF();
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
String type;
|
|
||||||
|
|
||||||
switch (subchannel) {
|
|
||||||
case "PlayerList":
|
|
||||||
out.writeUTF("PlayerList");
|
|
||||||
Set<UUID> original = Collections.emptySet();
|
|
||||||
type = in.readUTF();
|
|
||||||
if (type.equals("ALL")) {
|
|
||||||
out.writeUTF("ALL");
|
|
||||||
original = plugin.getPlayers();
|
|
||||||
} else {
|
|
||||||
out.writeUTF(type);
|
|
||||||
try {
|
|
||||||
original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type);
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Set<String> players = new HashSet<>();
|
|
||||||
for (UUID uuid : original)
|
|
||||||
players.add(plugin.getUuidTranslator().getNameFromUuid(uuid, false));
|
|
||||||
out.writeUTF(Joiner.on(',').join(players));
|
|
||||||
break;
|
|
||||||
case "PlayerCount":
|
|
||||||
out.writeUTF("PlayerCount");
|
|
||||||
type = in.readUTF();
|
|
||||||
if (type.equals("ALL")) {
|
|
||||||
out.writeUTF("ALL");
|
|
||||||
out.writeInt(plugin.getCount());
|
|
||||||
} else {
|
|
||||||
out.writeUTF(type);
|
|
||||||
try {
|
|
||||||
out.writeInt(plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type).size());
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
out.writeInt(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "LastOnline":
|
|
||||||
String user = in.readUTF();
|
|
||||||
out.writeUTF("LastOnline");
|
|
||||||
out.writeUTF(user);
|
|
||||||
out.writeLong(plugin.getAbstractRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
|
||||||
break;
|
|
||||||
case "ServerPlayers":
|
|
||||||
String type1 = in.readUTF();
|
|
||||||
out.writeUTF("ServerPlayers");
|
|
||||||
Multimap<String, UUID> multimap = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
|
||||||
|
|
||||||
boolean includesUsers;
|
|
||||||
|
|
||||||
switch (type1) {
|
|
||||||
case "COUNT":
|
|
||||||
includesUsers = false;
|
|
||||||
break;
|
|
||||||
case "PLAYERS":
|
|
||||||
includesUsers = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// TODO: Should I raise an error?
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeUTF(type1);
|
|
||||||
|
|
||||||
if (includesUsers) {
|
|
||||||
Multimap<String, String> human = HashMultimap.create();
|
|
||||||
for (Map.Entry<String, UUID> entry : multimap.entries()) {
|
|
||||||
human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false));
|
|
||||||
}
|
|
||||||
serializeMultimap(human, true, out);
|
|
||||||
} else {
|
|
||||||
serializeMultiset(multimap.keys(), out);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Proxy":
|
|
||||||
out.writeUTF("Proxy");
|
|
||||||
out.writeUTF(plugin.getConfiguration().getProxyId());
|
|
||||||
break;
|
|
||||||
case "PlayerProxy":
|
|
||||||
String username = in.readUTF();
|
|
||||||
out.writeUTF("PlayerProxy");
|
|
||||||
out.writeUTF(username);
|
|
||||||
out.writeUTF(plugin.getAbstractRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
((Server) event.getSender()).sendData(currentChannel, out.toByteArray());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@EventHandler
|
|
||||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
|
||||||
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getAbstractRedisBungeeApi().getProxyId())) {
|
|
||||||
String message = event.getMessage();
|
|
||||||
if (message.startsWith("/"))
|
|
||||||
message = message.substring(1);
|
|
||||||
plugin.logInfo("Invoking command via PubSub: /" + message);
|
|
||||||
((Plugin) plugin).getProxy().getPluginManager().dispatchCommand(RedisBungeeCommandSender.getSingleton(), message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class RedisBungeeCommandSender implements CommandSender {
|
|
||||||
private static final RedisBungeeCommandSender singleton;
|
|
||||||
|
|
||||||
static {
|
|
||||||
singleton = new RedisBungeeCommandSender();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RedisBungeeCommandSender getSingleton() {
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "RedisBungee";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(String s) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessages(String... strings) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(BaseComponent... baseComponents) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(BaseComponent baseComponent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> getGroups() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addGroups(String... strings) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeGroups(String... strings) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(String s) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPermission(String s, boolean b) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> getPermissions() {
|
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,353 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.commands;
|
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.collect.HashMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains subclasses that are used for the commands RedisBungee overrides or includes: /glist, /find and /lastseen.
|
|
||||||
* <p>
|
|
||||||
* All classes use the {@link AbstractRedisBungeeAPI}.
|
|
||||||
*
|
|
||||||
* @author tuxed
|
|
||||||
* @since 0.2.3
|
|
||||||
*/
|
|
||||||
public class RedisBungeeCommands {
|
|
||||||
private static final BaseComponent[] NO_PLAYER_SPECIFIED =
|
|
||||||
new ComponentBuilder("You must specify a player name.").color(ChatColor.RED).create();
|
|
||||||
private static final BaseComponent[] PLAYER_NOT_FOUND =
|
|
||||||
new ComponentBuilder("No such player found.").color(ChatColor.RED).create();
|
|
||||||
private static final BaseComponent[] NO_COMMAND_SPECIFIED =
|
|
||||||
new ComponentBuilder("You must specify a command to be run.").color(ChatColor.RED).create();
|
|
||||||
|
|
||||||
private static String playerPlural(int num) {
|
|
||||||
return num == 1 ? num + " player is" : num + " players are";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class GlistCommand extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
|
|
||||||
public GlistCommand(RedisBungee plugin) {
|
|
||||||
super("glist", "bungeecord.command.list", "redisbungee", "rglist");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
|
||||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
int count = plugin.getAbstractRedisBungeeApi().getPlayerCount();
|
|
||||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW)
|
|
||||||
.append(playerPlural(count) + " currently online.").create();
|
|
||||||
if (args.length > 0 && args[0].equals("showall")) {
|
|
||||||
Multimap<String, UUID> serverToPlayers = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
|
||||||
Multimap<String, String> human = HashMultimap.create();
|
|
||||||
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
|
|
||||||
// if for any reason UUID translation fails just return the uuid as name, to make command finish executing.
|
|
||||||
String playerName = plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false);
|
|
||||||
human.put(entry.getKey(), playerName != null ? playerName : entry.getValue().toString());
|
|
||||||
}
|
|
||||||
for (String server : new TreeSet<>(serverToPlayers.keySet())) {
|
|
||||||
TextComponent serverName = new TextComponent();
|
|
||||||
serverName.setColor(ChatColor.GREEN);
|
|
||||||
serverName.setText("[" + server + "] ");
|
|
||||||
TextComponent serverCount = new TextComponent();
|
|
||||||
serverCount.setColor(ChatColor.YELLOW);
|
|
||||||
serverCount.setText("(" + serverToPlayers.get(server).size() + "): ");
|
|
||||||
TextComponent serverPlayers = new TextComponent();
|
|
||||||
serverPlayers.setColor(ChatColor.WHITE);
|
|
||||||
serverPlayers.setText(Joiner.on(", ").join(human.get(server)));
|
|
||||||
sender.sendMessage(serverName, serverCount, serverPlayers);
|
|
||||||
}
|
|
||||||
sender.sendMessage(playersOnline);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(playersOnline);
|
|
||||||
sender.sendMessage(new ComponentBuilder("To see all players online, use /glist showall.").color(ChatColor.YELLOW).create());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class FindCommand extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
|
|
||||||
public FindCommand(RedisBungee plugin) {
|
|
||||||
super("find", "bungeecord.command.find", "rfind");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
|
||||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (args.length > 0) {
|
|
||||||
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ServerInfo si = plugin.getProxy().getServerInfo(plugin.getAbstractRedisBungeeApi().getServerNameFor(uuid));
|
|
||||||
if (si != null) {
|
|
||||||
TextComponent message = new TextComponent();
|
|
||||||
message.setColor(ChatColor.BLUE);
|
|
||||||
message.setText(args[0] + " is on " + si.getName() + ".");
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class LastSeenCommand extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
|
|
||||||
public LastSeenCommand(RedisBungee plugin) {
|
|
||||||
super("lastseen", "redisbungee.command.lastseen", "rlastseen");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
|
||||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (args.length > 0) {
|
|
||||||
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
long secs = plugin.getAbstractRedisBungeeApi().getLastOnline(uuid);
|
|
||||||
TextComponent message = new TextComponent();
|
|
||||||
if (secs == 0) {
|
|
||||||
message.setColor(ChatColor.GREEN);
|
|
||||||
message.setText(args[0] + " is currently online.");
|
|
||||||
} else if (secs != -1) {
|
|
||||||
message.setColor(ChatColor.BLUE);
|
|
||||||
message.setText(args[0] + " was last online on " + new SimpleDateFormat().format(secs) + ".");
|
|
||||||
} else {
|
|
||||||
message.setColor(ChatColor.RED);
|
|
||||||
message.setText(args[0] + " has never been online.");
|
|
||||||
}
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class IpCommand extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
|
|
||||||
public IpCommand(RedisBungee plugin) {
|
|
||||||
super("ip", "redisbungee.command.ip", "playerip", "rip", "rplayerip");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
|
||||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (args.length > 0) {
|
|
||||||
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
InetAddress ia = plugin.getAbstractRedisBungeeApi().getPlayerIp(uuid);
|
|
||||||
if (ia != null) {
|
|
||||||
TextComponent message = new TextComponent();
|
|
||||||
message.setColor(ChatColor.GREEN);
|
|
||||||
message.setText(args[0] + " is connected from " + ia.toString() + ".");
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PlayerProxyCommand extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
|
|
||||||
public PlayerProxyCommand(RedisBungee plugin) {
|
|
||||||
super("pproxy", "redisbungee.command.pproxy");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
|
||||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (args.length > 0) {
|
|
||||||
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String proxy = plugin.getAbstractRedisBungeeApi().getProxy(uuid);
|
|
||||||
if (proxy != null) {
|
|
||||||
TextComponent message = new TextComponent();
|
|
||||||
message.setColor(ChatColor.GREEN);
|
|
||||||
message.setText(args[0] + " is connected to " + proxy + ".");
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SendToAll extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
|
|
||||||
public SendToAll(RedisBungee plugin) {
|
|
||||||
super("sendtoall", "redisbungee.command.sendtoall", "rsendtoall");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
|
||||||
if (args.length > 0) {
|
|
||||||
String command = Joiner.on(" ").skipNulls().join(args);
|
|
||||||
plugin.getAbstractRedisBungeeApi().sendProxyCommand(command);
|
|
||||||
TextComponent message = new TextComponent();
|
|
||||||
message.setColor(ChatColor.GREEN);
|
|
||||||
message.setText("Sent the command /" + command + " to all proxies.");
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_COMMAND_SPECIFIED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ServerId extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
|
|
||||||
public ServerId(RedisBungee plugin) {
|
|
||||||
super("serverid", "redisbungee.command.serverid", "rserverid");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
|
||||||
TextComponent textComponent = new TextComponent();
|
|
||||||
textComponent.setText("You are on " + plugin.getAbstractRedisBungeeApi().getProxyId() + ".");
|
|
||||||
textComponent.setColor(ChatColor.YELLOW);
|
|
||||||
sender.sendMessage(textComponent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ServerIds extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
public ServerIds(RedisBungee plugin) {
|
|
||||||
super("serverids", "redisbungee.command.serverids");
|
|
||||||
this.plugin =plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] strings) {
|
|
||||||
TextComponent textComponent = new TextComponent();
|
|
||||||
textComponent.setText("All server IDs: " + Joiner.on(", ").join(plugin.getAbstractRedisBungeeApi().getAllProxies()));
|
|
||||||
textComponent.setColor(ChatColor.YELLOW);
|
|
||||||
sender.sendMessage(textComponent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PlistCommand extends Command {
|
|
||||||
private final RedisBungee plugin;
|
|
||||||
|
|
||||||
public PlistCommand(RedisBungee plugin) {
|
|
||||||
super("plist", "redisbungee.command.plist", "rplist");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
|
||||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getProxyId();
|
|
||||||
if (!plugin.getProxiesIds().contains(proxy)) {
|
|
||||||
sender.sendMessage(new ComponentBuilder(proxy + " is not a valid proxy. See /serverids for valid proxies.").color(ChatColor.RED).create());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Set<UUID> players = plugin.getAbstractRedisBungeeApi().getPlayersOnProxy(proxy);
|
|
||||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW)
|
|
||||||
.append(playerPlural(players.size()) + " currently on proxy " + proxy + ".").create();
|
|
||||||
if (args.length >= 2 && args[1].equals("showall")) {
|
|
||||||
Multimap<String, UUID> serverToPlayers = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
|
||||||
Multimap<String, String> human = HashMultimap.create();
|
|
||||||
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
|
|
||||||
if (players.contains(entry.getValue())) {
|
|
||||||
human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String server : new TreeSet<>(human.keySet())) {
|
|
||||||
TextComponent serverName = new TextComponent();
|
|
||||||
serverName.setColor(ChatColor.RED);
|
|
||||||
serverName.setText("[" + server + "] ");
|
|
||||||
TextComponent serverCount = new TextComponent();
|
|
||||||
serverCount.setColor(ChatColor.YELLOW);
|
|
||||||
serverCount.setText("(" + human.get(server).size() + "): ");
|
|
||||||
TextComponent serverPlayers = new TextComponent();
|
|
||||||
serverPlayers.setColor(ChatColor.WHITE);
|
|
||||||
serverPlayers.setText(Joiner.on(", ").join(human.get(server)));
|
|
||||||
sender.sendMessage(serverName, serverCount, serverPlayers);
|
|
||||||
}
|
|
||||||
sender.sendMessage(playersOnline);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(playersOnline);
|
|
||||||
sender.sendMessage(new ComponentBuilder("To see all players online, use /plist " + proxy + " showall.").color(ChatColor.YELLOW).create());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.events;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent;
|
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is sent when a player connects to a new server. RedisBungee sends the event only when
|
|
||||||
* the proxy the player has been connected to is different than the local proxy.
|
|
||||||
* <p>
|
|
||||||
* This event corresponds to {@link net.md_5.bungee.api.event.ServerConnectedEvent}, and is fired
|
|
||||||
* asynchronously.
|
|
||||||
*
|
|
||||||
* @since 0.3.4
|
|
||||||
*/
|
|
||||||
public class PlayerChangedServerNetworkEvent extends Event implements IPlayerChangedServerNetworkEvent {
|
|
||||||
private final UUID uuid;
|
|
||||||
private final String previousServer;
|
|
||||||
private final String server;
|
|
||||||
|
|
||||||
public PlayerChangedServerNetworkEvent(UUID uuid, String previousServer, String server) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.previousServer = previousServer;
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreviousServer() {
|
|
||||||
return previousServer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.events;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent;
|
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is sent when a player joins the network. RedisBungee sends the event only when
|
|
||||||
* the proxy the player has been connected to is different than the local proxy.
|
|
||||||
* <p>
|
|
||||||
* This event corresponds to {@link net.md_5.bungee.api.event.PostLoginEvent}, and is fired
|
|
||||||
* asynchronously.
|
|
||||||
*
|
|
||||||
* @since 0.3.4
|
|
||||||
*/
|
|
||||||
public class PlayerJoinedNetworkEvent extends Event implements IPlayerJoinedNetworkEvent {
|
|
||||||
private final UUID uuid;
|
|
||||||
|
|
||||||
public PlayerJoinedNetworkEvent(UUID uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.events;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent;
|
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is sent when a player disconnects. RedisBungee sends the event only when
|
|
||||||
* the proxy the player has been connected to is different than the local proxy.
|
|
||||||
* <p>
|
|
||||||
* This event corresponds to {@link net.md_5.bungee.api.event.PlayerDisconnectEvent}, and is fired
|
|
||||||
* asynchronously.
|
|
||||||
*
|
|
||||||
* @since 0.3.4
|
|
||||||
*/
|
|
||||||
public class PlayerLeftNetworkEvent extends Event implements IPlayerLeftNetworkEvent {
|
|
||||||
private final UUID uuid;
|
|
||||||
|
|
||||||
public PlayerLeftNetworkEvent(UUID uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.events;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent;
|
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is posted when a PubSub message is received.
|
|
||||||
* <p>
|
|
||||||
* <strong>Warning</strong>: This event is fired in a separate thread!
|
|
||||||
*
|
|
||||||
* @since 0.2.6
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class PubSubMessageEvent extends Event implements IPubSubMessageEvent {
|
|
||||||
private final String channel;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
public PubSubMessageEvent(String channel, String message) {
|
|
||||||
this.channel = channel;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChannel() {
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
name: RedisBungee
|
|
||||||
main: com.imaginarycode.minecraft.redisbungee.RedisBungee
|
|
||||||
version: ${project.parent.version}
|
|
||||||
author: "astei, ProxioDev"
|
|
||||||
# This is used so that we can automatically override default BungeeCord behavior.
|
|
||||||
softDepends: ["cmd_find", "cmd_list"]
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>RedisBungee</artifactId>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<version>0.10.2-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>RedisBungee-Velocity</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>papermc-repo</id>
|
|
||||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>templating-maven-plugin</artifactId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>add-plugin-info</id>
|
|
||||||
<goals>
|
|
||||||
<goal>filter-sources</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>11</source>
|
|
||||||
<target>11</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<version>3.3.2</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-javadocs</id>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<includeDependencySources>true</includeDependencySources>
|
|
||||||
<dependencySourceExcludes>
|
|
||||||
<dependencySourceExclude>com.velocitypowered:*</dependencySourceExclude>
|
|
||||||
</dependencySourceExcludes>
|
|
||||||
<source>11</source>
|
|
||||||
<destDir>../javadoc/${project.name}</destDir>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.2.4</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>redis.clients.jedis</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>redis.clients.util</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.apache.commons.pool</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.squareup.okhttp</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okhttp
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>okio</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okio</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.json</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.json</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.checkerframework</pattern>
|
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.checkframework
|
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<artifactId>RedisBungee-API</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>configurate-yaml</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
|
||||||
<artifactId>RedisBungee-API</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<classifier>javadoc</classifier>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>configurate-yaml</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.velocitypowered</groupId>
|
|
||||||
<artifactId>velocity-api</artifactId>
|
|
||||||
<version>3.1.2-SNAPSHOT</version>
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
public class PomData {
|
|
||||||
public final static String VERSION = "${project.parent.version}";
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
|
||||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This platform class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungeeAPI#getRedisBungeeApi()}
|
|
||||||
* or somehow you got the Plugin instance by you can call the api using {@link RedisBungeePlugin#getAbstractRedisBungeeApi()}.
|
|
||||||
*
|
|
||||||
* @author tuxed
|
|
||||||
* @since 0.2.3 | updated 0.8.0
|
|
||||||
*/
|
|
||||||
public class RedisBungeeAPI extends AbstractRedisBungeeAPI {
|
|
||||||
|
|
||||||
private static RedisBungeeAPI redisBungeeApi;
|
|
||||||
|
|
||||||
public RedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
|
||||||
super(plugin);
|
|
||||||
if (redisBungeeApi == null) {
|
|
||||||
redisBungeeApi = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the server where the specified player is playing. This function also deals with the case of local players
|
|
||||||
* as well, and will return local information on them.
|
|
||||||
*
|
|
||||||
* @param player a player uuid
|
|
||||||
* @return {@link ServerInfo} Can be null if proxy can't find it.
|
|
||||||
* @see #getServerNameFor(UUID)
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public final ServerInfo getServerFor(@NonNull UUID player) {
|
|
||||||
String serverName = this.getServerNameFor(player);
|
|
||||||
if (serverName == null) return null;
|
|
||||||
return ((RedisBungeeVelocityPlugin) this.plugin).getProxy().getServer(serverName).map((RegisteredServer::getServerInfo)).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Api instance
|
|
||||||
*
|
|
||||||
* @return the API instance.
|
|
||||||
* @since 0.6.5
|
|
||||||
*/
|
|
||||||
public static RedisBungeeAPI getRedisBungeeApi() {
|
|
||||||
return redisBungeeApi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
import com.velocitypowered.api.permission.Tristate;
|
|
||||||
import net.kyori.adventure.permission.PermissionChecker;
|
|
||||||
|
|
||||||
public class RedisBungeeCommandSource implements CommandSource {
|
|
||||||
private static final RedisBungeeCommandSource singleton;
|
|
||||||
private final PermissionChecker permissionChecker = PermissionChecker.always(net.kyori.adventure.util.TriState.TRUE);
|
|
||||||
|
|
||||||
static {
|
|
||||||
singleton = new RedisBungeeCommandSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RedisBungeeCommandSource getSingleton() {
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(String permission) {
|
|
||||||
return this.permissionChecker.test(permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tristate getPermissionValue(String s) {
|
|
||||||
return Tristate.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionChecker getPermissionChecker() {
|
|
||||||
return this.permissionChecker;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,263 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.collect.HashMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractRedisBungeeListener;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
|
||||||
import com.velocitypowered.api.event.Continuation;
|
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
|
||||||
import com.velocitypowered.api.event.ResultedEvent;
|
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
|
||||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
|
||||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
|
||||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
|
||||||
import com.velocitypowered.api.event.connection.PluginMessageEvent.ForwardResult;
|
|
||||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
|
||||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
|
||||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.Serializations.serializeMultimap;
|
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.Serializations.serializeMultiset;
|
|
||||||
|
|
||||||
public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<LoginEvent, PostLoginEvent, DisconnectEvent, ServerConnectedEvent, ProxyPingEvent, PluginMessageEvent, PubSubMessageEvent> {
|
|
||||||
// Some messages are using legacy characters
|
|
||||||
private final LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection();
|
|
||||||
|
|
||||||
public RedisBungeeVelocityListener(RedisBungeePlugin<?> plugin, List<InetAddress> exemptAddresses) {
|
|
||||||
super(plugin, exemptAddresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
|
||||||
public void onLogin(LoginEvent event, Continuation continuation) {
|
|
||||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
try {
|
|
||||||
if (!event.getResult().isAllowed()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (plugin.getConfiguration().restoreOldKickBehavior()) {
|
|
||||||
|
|
||||||
for (String s : plugin.getProxiesIds()) {
|
|
||||||
if (unifiedJedis.sismember("proxy:" + s + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
|
|
||||||
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN))));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (api.isPlayerOnline(event.getPlayer().getUniqueId())) {
|
|
||||||
PlayerUtils.setKickedOtherLocation(event.getPlayer().getUniqueId().toString(), unifiedJedis);
|
|
||||||
api.kickPlayer(event.getPlayer().getUniqueId(), plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
continuation.resume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe
|
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
|
||||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getUsername(), event.getPlayer().getUniqueId(), unifiedJedis);
|
|
||||||
VelocityPlayerUtils.createVelocityPlayer(event.getPlayer(), unifiedJedis, true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe
|
|
||||||
public void onPlayerDisconnect(DisconnectEvent event) {
|
|
||||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
PlayerUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), unifiedJedis, true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe
|
|
||||||
public void onServerChange(ServerConnectedEvent event) {
|
|
||||||
final String currentServer = event.getServer().getServerInfo().getName();
|
|
||||||
final String oldServer = event.getPreviousServer().map(serverConnection -> serverConnection.getServerInfo().getName()).orElse(null);
|
|
||||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
|
||||||
@Override
|
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
|
||||||
unifiedJedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", currentServer);
|
|
||||||
PayloadUtils.playerServerChangePayload(event.getPlayer().getUniqueId(), unifiedJedis, currentServer, oldServer);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe(order = PostOrder.EARLY)
|
|
||||||
public void onPing(ProxyPingEvent event) {
|
|
||||||
if (exemptAddresses.contains(event.getConnection().getRemoteAddress().getAddress())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ServerPing.Builder ping = event.getPing().asBuilder();
|
|
||||||
ping.onlinePlayers(plugin.getCount());
|
|
||||||
event.setPing(ping.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe
|
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
|
||||||
if (!(event.getSource() instanceof ServerConnection) || !RedisBungeeVelocityPlugin.IDENTIFIERS.contains(event.getIdentifier())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setResult(ForwardResult.handled());
|
|
||||||
|
|
||||||
plugin.executeAsync(() -> {
|
|
||||||
ByteArrayDataInput in = event.dataAsDataStream();
|
|
||||||
|
|
||||||
String subchannel = in.readUTF();
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
String type;
|
|
||||||
|
|
||||||
switch (subchannel) {
|
|
||||||
case "PlayerList":
|
|
||||||
out.writeUTF("PlayerList");
|
|
||||||
Set<UUID> original = Collections.emptySet();
|
|
||||||
type = in.readUTF();
|
|
||||||
if (type.equals("ALL")) {
|
|
||||||
out.writeUTF("ALL");
|
|
||||||
original = plugin.getPlayers();
|
|
||||||
} else {
|
|
||||||
out.writeUTF(type);
|
|
||||||
try {
|
|
||||||
original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type);
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Set<String> players = original.stream()
|
|
||||||
.map(uuid -> plugin.getUuidTranslator().getNameFromUuid(uuid, false))
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
out.writeUTF(Joiner.on(',').join(players));
|
|
||||||
break;
|
|
||||||
case "PlayerCount":
|
|
||||||
out.writeUTF("PlayerCount");
|
|
||||||
type = in.readUTF();
|
|
||||||
if (type.equals("ALL")) {
|
|
||||||
out.writeUTF("ALL");
|
|
||||||
out.writeInt(plugin.getCount());
|
|
||||||
} else {
|
|
||||||
out.writeUTF(type);
|
|
||||||
try {
|
|
||||||
out.writeInt(plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type).size());
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
out.writeInt(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "LastOnline":
|
|
||||||
String user = in.readUTF();
|
|
||||||
out.writeUTF("LastOnline");
|
|
||||||
out.writeUTF(user);
|
|
||||||
out.writeLong(plugin.getAbstractRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
|
||||||
break;
|
|
||||||
case "ServerPlayers":
|
|
||||||
String type1 = in.readUTF();
|
|
||||||
out.writeUTF("ServerPlayers");
|
|
||||||
Multimap<String, UUID> multimap = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
|
||||||
|
|
||||||
boolean includesUsers;
|
|
||||||
|
|
||||||
switch (type1) {
|
|
||||||
case "COUNT":
|
|
||||||
includesUsers = false;
|
|
||||||
break;
|
|
||||||
case "PLAYERS":
|
|
||||||
includesUsers = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// TODO: Should I raise an error?
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeUTF(type1);
|
|
||||||
|
|
||||||
if (includesUsers) {
|
|
||||||
Multimap<String, String> human = HashMultimap.create();
|
|
||||||
for (Map.Entry<String, UUID> entry : multimap.entries()) {
|
|
||||||
human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false));
|
|
||||||
}
|
|
||||||
serializeMultimap(human, true, out);
|
|
||||||
} else {
|
|
||||||
serializeMultiset(multimap.keys(), out);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Proxy":
|
|
||||||
out.writeUTF("Proxy");
|
|
||||||
out.writeUTF(plugin.getConfiguration().getProxyId());
|
|
||||||
break;
|
|
||||||
case "PlayerProxy":
|
|
||||||
String username = in.readUTF();
|
|
||||||
out.writeUTF("PlayerProxy");
|
|
||||||
out.writeUTF(username);
|
|
||||||
out.writeUTF(plugin.getAbstractRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
((ServerConnection) event.getSource()).sendPluginMessage(event.getIdentifier(), out.toByteArray());
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe
|
|
||||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
|
||||||
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getAbstractRedisBungeeApi().getProxyId())) {
|
|
||||||
String message = event.getMessage();
|
|
||||||
if (message.startsWith("/"))
|
|
||||||
message = message.substring(1);
|
|
||||||
plugin.logInfo("Invoking command via PubSub: /" + message);
|
|
||||||
((RedisBungeeVelocityPlugin) plugin).getProxy().getCommandManager().executeAsync(RedisBungeeCommandSource.getSingleton(), message);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,379 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.*;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.config.ConfigLoader;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.*;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.NameFetcher;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDFetcher;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.commands.RedisBungeeCommands;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
|
||||||
import com.squareup.okhttp.Dispatcher;
|
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
|
||||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
|
||||||
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
|
||||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
|
||||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import redis.clients.jedis.*;
|
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
@Plugin(id = "redisbungee", name = "RedisBungee", version = PomData.VERSION, url = "https://github.com/ProxioDev/RedisBungee", authors = {"astei", "ProxioDev"})
|
|
||||||
public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, ConfigLoader {
|
|
||||||
private final ProxyServer server;
|
|
||||||
private final Logger logger;
|
|
||||||
private final Path dataFolder;
|
|
||||||
private final AbstractRedisBungeeAPI api;
|
|
||||||
private final PubSubListener psl;
|
|
||||||
private Summoner<?> jedisSummoner;
|
|
||||||
private RedisBungeeMode redisBungeeMode;
|
|
||||||
private final UUIDTranslator uuidTranslator;
|
|
||||||
private RedisBungeeConfiguration configuration;
|
|
||||||
private final VelocityDataManager dataManager;
|
|
||||||
private final OkHttpClient httpClient;
|
|
||||||
private volatile List<String> proxiesIds;
|
|
||||||
private final AtomicInteger globalPlayerCount = new AtomicInteger();
|
|
||||||
private ScheduledTask integrityCheck;
|
|
||||||
private ScheduledTask heartbeatTask;
|
|
||||||
|
|
||||||
private static final Object SERVER_TO_PLAYERS_KEY = new Object();
|
|
||||||
public static final List<ChannelIdentifier> IDENTIFIERS = List.of(
|
|
||||||
MinecraftChannelIdentifier.create("legacy", "redisbungee"),
|
|
||||||
new LegacyChannelIdentifier("RedisBungee"),
|
|
||||||
// This is needed for clients before 1.13
|
|
||||||
new LegacyChannelIdentifier("legacy:redisbungee")
|
|
||||||
);
|
|
||||||
private final Cache<Object, Multimap<String, UUID>> serverToPlayersCache = CacheBuilder.newBuilder()
|
|
||||||
.expireAfterWrite(5, TimeUnit.SECONDS)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public RedisBungeeVelocityPlugin(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
|
|
||||||
this.server = server;
|
|
||||||
this.logger = logger;
|
|
||||||
this.dataFolder = dataDirectory;
|
|
||||||
try {
|
|
||||||
loadConfig(this, dataDirectory);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Unable to load/save config", e);
|
|
||||||
} catch (JedisConnectionException e) {
|
|
||||||
throw new RuntimeException("Unable to connect to your Redis server!", e);
|
|
||||||
}
|
|
||||||
this.api = new RedisBungeeAPI(this);
|
|
||||||
InitialUtils.checkRedisVersion(this);
|
|
||||||
// check if this proxy is recovering from a crash and start heart the beat.
|
|
||||||
InitialUtils.checkIfRecovering(this, getDataFolder());
|
|
||||||
uuidTranslator = new UUIDTranslator(this);
|
|
||||||
dataManager = new VelocityDataManager(this);
|
|
||||||
psl = new PubSubListener(this);
|
|
||||||
this.httpClient = new OkHttpClient();
|
|
||||||
Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(6));
|
|
||||||
this.httpClient.setDispatcher(dispatcher);
|
|
||||||
//NameFetcher.setHttpClient(httpClient);
|
|
||||||
UUIDFetcher.setHttpClient(httpClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RedisBungeeConfiguration getConfiguration() {
|
|
||||||
return this.configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return this.globalPlayerCount.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getLocalPlayersAsUuidStrings() {
|
|
||||||
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
|
|
||||||
for (Player player : getProxy().getAllPlayers()) {
|
|
||||||
builder.add(player.getUniqueId().toString());
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AbstractDataManager<Player, ?, ?, ?> getDataManager() {
|
|
||||||
return this.dataManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Summoner<?> getSummoner() {
|
|
||||||
return this.jedisSummoner;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AbstractRedisBungeeAPI getAbstractRedisBungeeApi() {
|
|
||||||
return this.api;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUIDTranslator getUuidTranslator() {
|
|
||||||
return this.uuidTranslator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Multimap<String, UUID> serverToPlayersCache() {
|
|
||||||
try {
|
|
||||||
return this.serverToPlayersCache.get(SERVER_TO_PLAYERS_KEY, this::serversToPlayers);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getProxiesIds() {
|
|
||||||
return proxiesIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PubSubListener getPubSubListener() {
|
|
||||||
return this.psl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeAsync(Runnable runnable) {
|
|
||||||
this.getProxy().getScheduler().buildTask(this, runnable).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeAsyncAfter(Runnable runnable, TimeUnit timeUnit, int time) {
|
|
||||||
this.getProxy().getScheduler().buildTask(this, runnable).delay(time, timeUnit).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fireEvent(Object event) {
|
|
||||||
this.getProxy().getEventManager().fireAndForget(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOnlineMode() {
|
|
||||||
return this.getProxy().getConfiguration().isOnlineMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logInfo(String msg) {
|
|
||||||
this.getLogger().info(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logWarn(String msg) {
|
|
||||||
this.getLogger().warn(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logFatal(String msg) {
|
|
||||||
this.getLogger().error(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Player getPlayer(UUID uuid) {
|
|
||||||
return this.getProxy().getPlayer(uuid).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Player getPlayer(String name) {
|
|
||||||
return this.getProxy().getPlayer(name).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getPlayerUUID(String player) {
|
|
||||||
return this.getProxy().getPlayer(player).map(Player::getUniqueId).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPlayerName(UUID player) {
|
|
||||||
return this.getProxy().getPlayer(player).map(Player::getUsername).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPlayerServerName(Player player) {
|
|
||||||
return player.getCurrentServer().map(serverConnection -> serverConnection.getServerInfo().getName()).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPlayerOnAServer(Player player) {
|
|
||||||
return player.getCurrentServer().isPresent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InetAddress getPlayerIp(Player player) {
|
|
||||||
return player.getRemoteAddress().getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize() {
|
|
||||||
updateProxiesIds();
|
|
||||||
// start heartbeat task
|
|
||||||
heartbeatTask = getProxy().getScheduler().buildTask(this, new HeartbeatTask(this, this.globalPlayerCount)).repeat(HeartbeatTask.INTERVAL, HeartbeatTask.REPEAT_INTERVAL_TIME_UNIT).schedule();
|
|
||||||
|
|
||||||
getProxy().getEventManager().register(this, new RedisBungeeVelocityListener(this, configuration.getExemptAddresses()));
|
|
||||||
getProxy().getEventManager().register(this, dataManager);
|
|
||||||
getProxy().getScheduler().buildTask(this, psl).schedule();
|
|
||||||
|
|
||||||
IntegrityCheckTask integrityCheckTask = new IntegrityCheckTask(this) {
|
|
||||||
@Override
|
|
||||||
public void handlePlatformPlayer(String player, UnifiedJedis unifiedJedis) {
|
|
||||||
Player playerProxied = getProxy().getPlayer(UUID.fromString(player)).orElse(null);
|
|
||||||
if (playerProxied == null)
|
|
||||||
return; // We'll deal with it later.
|
|
||||||
VelocityPlayerUtils.createVelocityPlayer(playerProxied, unifiedJedis, false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
integrityCheck = getProxy().getScheduler().buildTask(this, integrityCheckTask::execute).repeat(30, TimeUnit.SECONDS).schedule();
|
|
||||||
|
|
||||||
|
|
||||||
// register plugin messages
|
|
||||||
IDENTIFIERS.forEach(getProxy().getChannelRegistrar()::register);
|
|
||||||
|
|
||||||
// register legacy commands
|
|
||||||
if (configuration.doRegisterLegacyCommands()) {
|
|
||||||
// Override Velocity commands
|
|
||||||
if (configuration.doOverrideBungeeCommands()) {
|
|
||||||
getProxy().getCommandManager().register("glist", new RedisBungeeCommands.GlistCommand(this), "redisbungee", "rglist");
|
|
||||||
}
|
|
||||||
getProxy().getCommandManager().register("sendtoall", new RedisBungeeCommands.SendToAll(this), "rsendtoall");
|
|
||||||
getProxy().getCommandManager().register("serverid", new RedisBungeeCommands.ServerId(this), "rserverid");
|
|
||||||
getProxy().getCommandManager().register("serverids", new RedisBungeeCommands.ServerIds(this));
|
|
||||||
getProxy().getCommandManager().register("pproxy", new RedisBungeeCommands.PlayerProxyCommand(this));
|
|
||||||
getProxy().getCommandManager().register("plist", new RedisBungeeCommands.PlistCommand(this), "rplist");
|
|
||||||
getProxy().getCommandManager().register("lastseen", new RedisBungeeCommands.LastSeenCommand(this), "rlastseen");
|
|
||||||
getProxy().getCommandManager().register("ip", new RedisBungeeCommands.IpCommand(this), "playerip", "rip", "rplayerip");
|
|
||||||
getProxy().getCommandManager().register("find", new RedisBungeeCommands.FindCommand(this), "rfind");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
// Poison the PubSub listener
|
|
||||||
if (psl != null) {
|
|
||||||
psl.poison();
|
|
||||||
}
|
|
||||||
if (integrityCheck != null) {
|
|
||||||
integrityCheck.cancel();
|
|
||||||
}
|
|
||||||
if (heartbeatTask != null) {
|
|
||||||
heartbeatTask.cancel();
|
|
||||||
}
|
|
||||||
ShutdownUtils.shutdownCleanup(this);
|
|
||||||
try {
|
|
||||||
this.jedisSummoner.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.httpClient.getDispatcher().getExecutorService().shutdown();
|
|
||||||
try {
|
|
||||||
this.httpClient.getDispatcher().getExecutorService().awaitTermination(20, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfigLoad(RedisBungeeConfiguration configuration, Summoner<?> summoner, RedisBungeeMode mode) {
|
|
||||||
this.jedisSummoner = summoner;
|
|
||||||
this.configuration = configuration;
|
|
||||||
this.redisBungeeMode = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RedisBungeeMode getRedisBungeeMode() {
|
|
||||||
return this.redisBungeeMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateProxiesIds() {
|
|
||||||
this.proxiesIds = this.getCurrentProxiesIds(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void proxyInit(ProxyInitializeEvent event) {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void proxyShutdownEvent(ProxyShutdownEvent event) {
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPlayerChangedServerNetworkEvent createPlayerChangedServerNetworkEvent(UUID uuid, String previousServer, String server) {
|
|
||||||
return new PlayerChangedServerNetworkEvent(uuid, previousServer, server);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPlayerJoinedNetworkEvent createPlayerJoinedNetworkEvent(UUID uuid) {
|
|
||||||
return new PlayerJoinedNetworkEvent(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPlayerLeftNetworkEvent createPlayerLeftNetworkEvent(UUID uuid) {
|
|
||||||
return new PlayerLeftNetworkEvent(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPubSubMessageEvent createPubSubEvent(String channel, String message) {
|
|
||||||
return new PubSubMessageEvent(channel, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProxyServer getProxy() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getLogger() {
|
|
||||||
return logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Path getDataFolder() {
|
|
||||||
return this.dataFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getResourceAsStream(String name) {
|
|
||||||
return this.getClass().getClassLoader().getResourceAsStream(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
|
||||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.TextComponent;
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
|
|
||||||
public class VelocityDataManager extends AbstractDataManager<Player, PostLoginEvent, DisconnectEvent, PubSubMessageEvent> {
|
|
||||||
|
|
||||||
public VelocityDataManager(RedisBungeePlugin<Player> plugin) {
|
|
||||||
super(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe
|
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
|
||||||
invalidate(event.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe
|
|
||||||
public void onPlayerDisconnect(DisconnectEvent event) {
|
|
||||||
invalidate(event.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Subscribe
|
|
||||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
|
||||||
handlePubSubMessage(event.getChannel(), event.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private final LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection();
|
|
||||||
@Override
|
|
||||||
public boolean handleKick(UUID target, String message) {
|
|
||||||
Player player = plugin.getPlayer(target);
|
|
||||||
if (player == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
player.disconnect(serializer.deserialize(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class VelocityPlayerUtils {
|
|
||||||
protected static void createVelocityPlayer(Player player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
|
||||||
Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
|
|
||||||
String serverName = null;
|
|
||||||
if (optionalServerConnection.isPresent()) {
|
|
||||||
serverName = optionalServerConnection.get().getServerInfo().getName();
|
|
||||||
}
|
|
||||||
PlayerUtils.createPlayer(player.getUniqueId(), unifiedJedis, serverName, player.getRemoteAddress().getAddress(), fireEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,362 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.commands;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.collect.HashMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeVelocityPlugin;
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
import com.velocitypowered.api.command.SimpleCommand;
|
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
|
||||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.TextComponent;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains subclasses that are used for the commands RedisBungee overrides or includes: /glist, /find and /lastseen.
|
|
||||||
* <p>
|
|
||||||
* All classes use the {@link AbstractRedisBungeeAPI}.
|
|
||||||
*
|
|
||||||
* @author tuxed
|
|
||||||
* @since 0.2.3
|
|
||||||
*/
|
|
||||||
public class RedisBungeeCommands {
|
|
||||||
|
|
||||||
private static final Component NO_PLAYER_SPECIFIED =
|
|
||||||
Component.text("You must specify a player name.", NamedTextColor.RED);
|
|
||||||
private static final Component PLAYER_NOT_FOUND =
|
|
||||||
Component.text("No such player found.", NamedTextColor.RED);
|
|
||||||
private static final Component NO_COMMAND_SPECIFIED =
|
|
||||||
Component.text("You must specify a command to be run.", NamedTextColor.RED);
|
|
||||||
|
|
||||||
private static String playerPlural(int num) {
|
|
||||||
return num == 1 ? num + " player is" : num + " players are";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class GlistCommand implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public GlistCommand(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final Invocation invocation) {
|
|
||||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
|
||||||
int count = plugin.getAbstractRedisBungeeApi().getPlayerCount();
|
|
||||||
Component playersOnline = Component.text(playerPlural(count) + " currently online.", NamedTextColor.YELLOW);
|
|
||||||
CommandSource sender = invocation.source();
|
|
||||||
if (invocation.arguments().length > 0 && invocation.arguments()[0].equals("showall")) {
|
|
||||||
Multimap<String, UUID> serverToPlayers = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
|
||||||
Multimap<String, String> human = HashMultimap.create();
|
|
||||||
serverToPlayers.forEach((key, value) -> {
|
|
||||||
// if for any reason UUID translation fails just return the uuid as name, to make command finish executing.
|
|
||||||
String playerName = plugin.getUuidTranslator().getNameFromUuid(value, false);
|
|
||||||
human.put(key, playerName != null ? playerName : value.toString());
|
|
||||||
});
|
|
||||||
for (String server : new TreeSet<>(serverToPlayers.keySet())) {
|
|
||||||
Component serverName = Component.text("[" + server + "] ", NamedTextColor.GREEN);
|
|
||||||
Component serverCount = Component.text("(" + serverToPlayers.get(server).size() + "): ", NamedTextColor.YELLOW);
|
|
||||||
Component serverPlayers = Component.text(Joiner.on(", ").join(human.get(server)), NamedTextColor.WHITE);
|
|
||||||
sender.sendMessage(Component.textOfChildren(serverName, serverCount, serverPlayers));
|
|
||||||
}
|
|
||||||
sender.sendMessage(playersOnline);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(playersOnline);
|
|
||||||
sender.sendMessage(Component.text("To see all players online, use /glist showall.", NamedTextColor.YELLOW));
|
|
||||||
}
|
|
||||||
}).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("velocity.command.server");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class FindCommand implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public FindCommand(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final Invocation invocation) {
|
|
||||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
|
||||||
String[] args = invocation.arguments();
|
|
||||||
CommandSource sender = invocation.source();
|
|
||||||
if (args.length > 0) {
|
|
||||||
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ServerInfo si = plugin.getProxy().getServer(plugin.getAbstractRedisBungeeApi().getServerNameFor(uuid)).map(RegisteredServer::getServerInfo).orElse(null);
|
|
||||||
if (si != null) {
|
|
||||||
Component message = Component.text(args[0] + " is on " + si.getName() + ".", NamedTextColor.BLUE);
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
|
||||||
}
|
|
||||||
}).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("redisbungee.command.find");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class LastSeenCommand implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public LastSeenCommand(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final Invocation invocation) {
|
|
||||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
|
||||||
String[] args = invocation.arguments();
|
|
||||||
CommandSource sender = invocation.source();
|
|
||||||
if (args.length > 0) {
|
|
||||||
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
long secs = plugin.getAbstractRedisBungeeApi().getLastOnline(uuid);
|
|
||||||
TextComponent.Builder message = Component.text();
|
|
||||||
if (secs == 0) {
|
|
||||||
message.color(NamedTextColor.GREEN);
|
|
||||||
message.content(args[0] + " is currently online.");
|
|
||||||
} else if (secs != -1) {
|
|
||||||
message.color(NamedTextColor.BLUE);
|
|
||||||
message.content(args[0] + " was last online on " + new SimpleDateFormat().format(secs) + ".");
|
|
||||||
} else {
|
|
||||||
message.color(NamedTextColor.RED);
|
|
||||||
message.content(args[0] + " has never been online.");
|
|
||||||
}
|
|
||||||
sender.sendMessage(message.build());
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
|
||||||
}
|
|
||||||
}).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("redisbungee.command.lastseen");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class IpCommand implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public IpCommand(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final Invocation invocation) {
|
|
||||||
CommandSource sender = invocation.source();
|
|
||||||
String[] args = invocation.arguments();
|
|
||||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
|
||||||
if (args.length > 0) {
|
|
||||||
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
InetAddress ia = plugin.getAbstractRedisBungeeApi().getPlayerIp(uuid);
|
|
||||||
if (ia != null) {
|
|
||||||
TextComponent message = Component.text(args[0] + " is connected from " + ia.toString() + ".", NamedTextColor.GREEN);
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
|
||||||
}
|
|
||||||
}).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("redisbungee.command.ip");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PlayerProxyCommand implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public PlayerProxyCommand(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final Invocation invocation) {
|
|
||||||
CommandSource sender = invocation.source();
|
|
||||||
String[] args = invocation.arguments();
|
|
||||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
|
||||||
if (args.length > 0) {
|
|
||||||
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String proxy = plugin.getAbstractRedisBungeeApi().getProxy(uuid);
|
|
||||||
if (proxy != null) {
|
|
||||||
TextComponent message = Component.text(args[0] + " is connected to " + proxy + ".", NamedTextColor.GREEN);
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
|
||||||
}
|
|
||||||
}).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("redisbungee.command.pproxy");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SendToAll implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public SendToAll(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
//super("sendtoall", "redisbungee.command.sendtoall", "rsendtoall");
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final Invocation invocation) {
|
|
||||||
String[] args = invocation.arguments();
|
|
||||||
CommandSource sender = invocation.source();
|
|
||||||
if (args.length > 0) {
|
|
||||||
String command = Joiner.on(" ").skipNulls().join(args);
|
|
||||||
plugin.getAbstractRedisBungeeApi().sendProxyCommand(command);
|
|
||||||
TextComponent message = Component.text("Sent the command /" + command + " to all proxies.", NamedTextColor.GREEN);
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(NO_COMMAND_SPECIFIED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("redisbungee.command.sendtoall");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ServerId implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public ServerId(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(Invocation invocation) {
|
|
||||||
invocation.source().sendMessage(Component.text("You are on " + plugin.getAbstractRedisBungeeApi().getProxyId() + ".", NamedTextColor.YELLOW));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("redisbungee.command.serverid");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ServerIds implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public ServerIds(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(Invocation invocation) {
|
|
||||||
invocation.source().sendMessage(
|
|
||||||
Component.text("All server IDs: " + Joiner.on(", ").join(plugin.getAbstractRedisBungeeApi().getAllProxies()), NamedTextColor.YELLOW));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("redisbungee.command.serverids");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PlistCommand implements SimpleCommand {
|
|
||||||
private final RedisBungeeVelocityPlugin plugin;
|
|
||||||
|
|
||||||
public PlistCommand(RedisBungeeVelocityPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(Invocation invocation) {
|
|
||||||
CommandSource sender = invocation.source();
|
|
||||||
String[] args = invocation.arguments();
|
|
||||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
|
||||||
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getProxyId();
|
|
||||||
if (!plugin.getProxiesIds().contains(proxy)) {
|
|
||||||
sender.sendMessage(Component.text(proxy + " is not a valid proxy. See /serverids for valid proxies.", NamedTextColor.RED));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Set<UUID> players = plugin.getAbstractRedisBungeeApi().getPlayersOnProxy(proxy);
|
|
||||||
Component playersOnline = Component.text(playerPlural(players.size()) + " currently on proxy " + proxy + ".", NamedTextColor.YELLOW);
|
|
||||||
if (args.length >= 2 && args[1].equals("showall")) {
|
|
||||||
Multimap<String, UUID> serverToPlayers = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
|
||||||
Multimap<String, String> human = HashMultimap.create();
|
|
||||||
serverToPlayers.forEach((key, value) -> {
|
|
||||||
if (players.contains(value)) {
|
|
||||||
human.put(key, plugin.getUuidTranslator().getNameFromUuid(value, false));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (String server : new TreeSet<>(human.keySet())) {
|
|
||||||
TextComponent serverName = Component.text("[" + server + "] ", NamedTextColor.RED);
|
|
||||||
TextComponent serverCount = Component.text("(" + human.get(server).size() + "): ", NamedTextColor.YELLOW);
|
|
||||||
TextComponent serverPlayers = Component.text(Joiner.on(", ").join(human.get(server)), NamedTextColor.WHITE);
|
|
||||||
sender.sendMessage(Component.textOfChildren(serverName, serverCount, serverPlayers));
|
|
||||||
}
|
|
||||||
sender.sendMessage(playersOnline);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(playersOnline);
|
|
||||||
sender.sendMessage(Component.text("To see all players online, use /plist " + proxy + " showall.", NamedTextColor.YELLOW));
|
|
||||||
}
|
|
||||||
}).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Invocation invocation) {
|
|
||||||
return invocation.source().hasPermission("redisbungee.command.plist");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.events;
|
|
||||||
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is sent when a player connects to a new server. RedisBungee sends the event only when
|
|
||||||
* the proxy the player has been connected to is different than the local proxy.
|
|
||||||
* <p>
|
|
||||||
* This event corresponds to {@link com.velocitypowered.api.event.player.ServerConnectedEvent}, and is fired
|
|
||||||
* asynchronously.
|
|
||||||
*
|
|
||||||
* @since 0.3.4
|
|
||||||
*/
|
|
||||||
public class PlayerChangedServerNetworkEvent implements IPlayerChangedServerNetworkEvent {
|
|
||||||
private final UUID uuid;
|
|
||||||
private final String previousServer;
|
|
||||||
private final String server;
|
|
||||||
|
|
||||||
public PlayerChangedServerNetworkEvent(UUID uuid, String previousServer, String server) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.previousServer = previousServer;
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreviousServer() {
|
|
||||||
return previousServer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.events;
|
|
||||||
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is sent when a player joins the network. RedisBungee sends the event only when
|
|
||||||
* the proxy the player has been connected to is different than the local proxy.
|
|
||||||
* <p>
|
|
||||||
* This event corresponds to {@link com.velocitypowered.api.event.connection.PostLoginEvent}, and is fired
|
|
||||||
* asynchronously.
|
|
||||||
*
|
|
||||||
* @since 0.3.4
|
|
||||||
*/
|
|
||||||
public class PlayerJoinedNetworkEvent implements IPlayerJoinedNetworkEvent {
|
|
||||||
private final UUID uuid;
|
|
||||||
|
|
||||||
public PlayerJoinedNetworkEvent(UUID uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.events;
|
|
||||||
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is sent when a player disconnects. RedisBungee sends the event only when
|
|
||||||
* the proxy the player has been connected to is different than the local proxy.
|
|
||||||
* <p>
|
|
||||||
* This event corresponds to {@link com.velocitypowered.api.event.connection.DisconnectEvent}, and is fired
|
|
||||||
* asynchronously.
|
|
||||||
*
|
|
||||||
* @since 0.3.4
|
|
||||||
*/
|
|
||||||
public class PlayerLeftNetworkEvent implements IPlayerLeftNetworkEvent {
|
|
||||||
private final UUID uuid;
|
|
||||||
|
|
||||||
public PlayerLeftNetworkEvent(UUID uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-present RedisBungee contributors
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
*
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee.events;
|
|
||||||
|
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is posted when a PubSub message is received.
|
|
||||||
* <p>
|
|
||||||
* <strong>Warning</strong>: This event is fired in a separate thread!
|
|
||||||
*
|
|
||||||
* @since 0.2.6
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class PubSubMessageEvent implements IPubSubMessageEvent {
|
|
||||||
private final String channel;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
public PubSubMessageEvent(String channel, String message) {
|
|
||||||
this.channel = channel;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChannel() {
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
202
api/LICENSE
Normal file
202
api/LICENSE
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
23
api/build.gradle.kts
Normal file
23
api/build.gradle.kts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
plugins {
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
description = "Api functions for valiobungee"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation(libs.testing.juipter)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("maven") {
|
||||||
|
from(components["java"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
15
api/copyright_header.txt
Normal file
15
api/copyright_header.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.api;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkPlayer;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkProxy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The api interface
|
||||||
|
*
|
||||||
|
* @author Ham1255
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public interface ValioBungeeAPI {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param uuid of player
|
||||||
|
* @return {@link Optional} if empty player is offline and if present player on the network
|
||||||
|
*/
|
||||||
|
Optional<NetworkPlayer> getNetworkPlayer(UUID uuid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id the proxy id
|
||||||
|
* @return {@link Optional} if empty the proxy doesn't exist if present it's an online proxy
|
||||||
|
*/
|
||||||
|
Optional<NetworkProxy> getNetworkProxy(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the local proxy
|
||||||
|
*/
|
||||||
|
NetworkProxy getLocalProxy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the network proxies that is currently online including the local
|
||||||
|
*/
|
||||||
|
Set<NetworkProxy> getNetworkProxies();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the local players empty if no players
|
||||||
|
*/
|
||||||
|
Set<NetworkPlayer> getLocalProxyPlayers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the network players empty if no players
|
||||||
|
*/
|
||||||
|
Set<NetworkPlayer> getNetworkPlayers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Version based on the build
|
||||||
|
*/
|
||||||
|
String getVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return GIT COMMIT based on the build
|
||||||
|
*/
|
||||||
|
String getGitCommit();
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.api.entity;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Network player.
|
||||||
|
*
|
||||||
|
* @author Ham1255
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public interface NetworkPlayer {
|
||||||
|
/**
|
||||||
|
* @return proxy player on
|
||||||
|
*/
|
||||||
|
NetworkProxy getProxy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true when player is on the same proxy
|
||||||
|
*/
|
||||||
|
boolean isLocal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This used when we already had the object but player went offline since getting a player as
|
||||||
|
* {@link java.util.Optional} we check if its present if not means offline see {@link
|
||||||
|
* net.limework.valiobungee.api.ValioBungeeAPI#getNetworkPlayer(UUID)}
|
||||||
|
*
|
||||||
|
* @return true when a player is online on the network
|
||||||
|
*/
|
||||||
|
boolean isOnline();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return player unique id
|
||||||
|
*/
|
||||||
|
UUID getUniqueId();
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.api.entity;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proxy is an object for online proxy in a network
|
||||||
|
*
|
||||||
|
* @author Ham1255
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public interface NetworkProxy {
|
||||||
|
/**
|
||||||
|
* @return return the proxy id of this proxy
|
||||||
|
*/
|
||||||
|
String proxyId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return online players number in this proxy
|
||||||
|
*/
|
||||||
|
int onlinePlayerCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns set of players in this proxy
|
||||||
|
*/
|
||||||
|
Set<NetworkPlayer> getProxyPlayers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return returns true if this NetworkProxy is the same proxy
|
||||||
|
*/
|
||||||
|
boolean isMe();
|
||||||
|
}
|
||||||
33
api/velocity/build.gradle.kts
Normal file
33
api/velocity/build.gradle.kts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
plugins {
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly(libs.platform.velocity)
|
||||||
|
api(project(":valiobungee-api"))
|
||||||
|
}
|
||||||
|
|
||||||
|
description = "ValioBungee Velocity API"
|
||||||
|
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
withType<Javadoc> {
|
||||||
|
dependsOn(project(":valiobungee-api").getTasksByName("javadoc", false))
|
||||||
|
val options = options as StandardJavadocDocletOptions
|
||||||
|
options.use()
|
||||||
|
options.isDocFilesSubDirs = true
|
||||||
|
options.links(
|
||||||
|
"https://jd.papermc.io/velocity/3.5.0/", // velocity api
|
||||||
|
)
|
||||||
|
val apiDocs = File(rootProject.projectDir, "api/build/docs/javadoc")
|
||||||
|
//options.linksOffline("https://ci.limework.net/ValioBungee/api/build/docs/javadoc", apiDocs.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("maven") {
|
||||||
|
from(components["java"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.velocity.api;
|
||||||
|
|
||||||
|
import net.limework.valiobungee.api.ValioBungeeAPI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valiobungee velocity specific API
|
||||||
|
*
|
||||||
|
* @author Ham1255
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public interface VelocityValioBungeeAPI extends ValioBungeeAPI {}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.velocity.api.entities;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import java.util.Optional;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Velocity Network player. hold specific stuff for velocity platform
|
||||||
|
*
|
||||||
|
* @author Ham1255
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public interface VelocityNetworkPlayer extends NetworkPlayer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an optional that contains a player if he is on the same proxy
|
||||||
|
*/
|
||||||
|
Optional<Player> getHandle();
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.velocity.api.entities;
|
||||||
|
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkProxy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proxy is an object for online proxy in a velocity network
|
||||||
|
*
|
||||||
|
* @author Ham1255
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public interface VelocityNetworkProxy extends NetworkProxy {}
|
||||||
48
build.gradle.kts
Normal file
48
build.gradle.kts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
plugins {
|
||||||
|
`java-library`
|
||||||
|
alias { libs.plugins.spotless } apply false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
subprojects {
|
||||||
|
apply { plugin("com.diffplug.spotless") }
|
||||||
|
apply { plugin("java-library") }
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion.set(JavaLanguageVersion.of(21))
|
||||||
|
}
|
||||||
|
withJavadocJar()
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
javadoc {
|
||||||
|
options.encoding = Charsets.UTF_8.name()
|
||||||
|
}
|
||||||
|
processResources {
|
||||||
|
filteringCharset = Charsets.UTF_8.name()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
|
||||||
|
var redisBungeeProjects = sequenceOf("RedisBungee-API", "RedisBungee-Lang", "RedisBungee-Commands", "RedisBungee-Bungee", "RedisBungee-Proxy-Bungee", "RedisBungee-Velocity", "RedisBungee-Proxy-Velocity")
|
||||||
|
var apiProjects = sequenceOf("valiobungee-api", "valiobungee-velocity-api")
|
||||||
|
|
||||||
|
java {
|
||||||
|
removeUnusedImports()
|
||||||
|
googleJavaFormat()
|
||||||
|
if (apiProjects.contains(project.name)) {
|
||||||
|
licenseHeaderFile(rootProject.file("api/copyright_header.txt"))
|
||||||
|
} else if (redisBungeeProjects.contains(project.name)) {
|
||||||
|
licenseHeaderFile(rootProject.file("redisbungee/copyright_header.txt"))
|
||||||
|
} else {
|
||||||
|
licenseHeaderFile(rootProject.file("copyright_header.txt"))
|
||||||
|
}
|
||||||
|
if (project.name == "valiobungee-core") {
|
||||||
|
targetExclude("**/net/limework/valiobungee/core/proto/**")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
18
copyright_header.txt
Normal file
18
copyright_header.txt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
40
core/build.gradle.kts
Normal file
40
core/build.gradle.kts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
plugins {
|
||||||
|
alias(libs.plugins.blossom)
|
||||||
|
alias(libs.plugins.indragit)
|
||||||
|
alias(libs.plugins.protobuf)
|
||||||
|
}
|
||||||
|
|
||||||
|
description = "Core functions for valiobungee"
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
blossom {
|
||||||
|
javaSources {
|
||||||
|
property("version", version.toString())
|
||||||
|
property("git", indraGit.commit().get().name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api(project(":valiobungee-api"))
|
||||||
|
api(libs.protobuf)
|
||||||
|
api(libs.caffeine)
|
||||||
|
api(libs.slf4j)
|
||||||
|
testImplementation(libs.testing.juipter)
|
||||||
|
testImplementation(libs.testing.slf4j.simple)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
protobuf {
|
||||||
|
protoc {
|
||||||
|
artifact = libs.protoc.get().toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
9
core/redisson/build.gradle.kts
Normal file
9
core/redisson/build.gradle.kts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
dependencies {
|
||||||
|
compileOnly(project(":valiobungee-core"))
|
||||||
|
api(libs.redisson)
|
||||||
|
}
|
||||||
|
|
||||||
|
description = "ValioBungee Redisson implementation"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core;
|
||||||
|
|
||||||
|
public class ConstantVariables {
|
||||||
|
|
||||||
|
public static final String VERSION = "{{ version }}";
|
||||||
|
public static final String GIT_COMMIT = "{{ git }}";
|
||||||
|
|
||||||
|
public static String getGithubCommitLink() {
|
||||||
|
return "https://github.com/ProxioDev/ValioBungee/commit/" + GIT_COMMIT;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkPlayer;
|
||||||
|
|
||||||
|
public abstract class PlayerManager {
|
||||||
|
|
||||||
|
protected final ValioBungeePlatform platform;
|
||||||
|
|
||||||
|
public PlayerManager(ValioBungeePlatform platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Optional<NetworkPlayer> getNetworkPlayer(UUID uuid);
|
||||||
|
|
||||||
|
public abstract Set<NetworkPlayer> getNetworkPlayers();
|
||||||
|
|
||||||
|
public abstract boolean isOnline(UUID uuid);
|
||||||
|
|
||||||
|
public abstract void handleJoin(UUID uuid);
|
||||||
|
|
||||||
|
public abstract void handleQuit(UUID uuid);
|
||||||
|
|
||||||
|
public abstract void correctionTask();
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core;
|
||||||
|
|
||||||
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
|
import com.github.benmanes.caffeine.cache.RemovalCause;
|
||||||
|
import com.github.benmanes.caffeine.cache.RemovalListener;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkProxy;
|
||||||
|
import net.limework.valiobungee.core.proto.messages.*;
|
||||||
|
import net.limework.valiobungee.core.util.logging.LogProviderFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This abstract class is responsible for proxy discovery and count online players as its cached
|
||||||
|
* locally Why abstract? Because it allows us to develop alternative implementation to use other
|
||||||
|
* software than valkey or redis
|
||||||
|
*/
|
||||||
|
public abstract class ProxyNetworkManager {
|
||||||
|
|
||||||
|
protected final UUID proxyManagerId = UUID.randomUUID();
|
||||||
|
protected final ValioBungeePlatform platform;
|
||||||
|
|
||||||
|
public ProxyNetworkManager(ValioBungeePlatform platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Logger log = LogProviderFactory.get();
|
||||||
|
|
||||||
|
// proxy info class here stores the ProxyManager ID hence we use another cache for online players
|
||||||
|
// reason we use caffeine cache it allows us to auto remove entries without need for scheduled
|
||||||
|
// tasks in the proxies when a proxy disappears without sending death message
|
||||||
|
private final Cache<String, Heartbeat> heartbeats =
|
||||||
|
Caffeine.newBuilder()
|
||||||
|
.expireAfterWrite(Duration.ofSeconds(30))
|
||||||
|
.removalListener(
|
||||||
|
(RemovalListener<String, Heartbeat>)
|
||||||
|
(key, value, cause) -> {
|
||||||
|
if (cause == RemovalCause.EXPIRED) {
|
||||||
|
assert value != null;
|
||||||
|
log.warn("proxy {} has disconnected but did not send death message", key);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
protected void handleProxyHeartBeat(Heartbeat payload) {
|
||||||
|
if (!this.heartbeats.asMap().containsKey(payload.getSender().getProxyId()))
|
||||||
|
log.info("Proxy {} has connected!", payload.getSender().getProxyId());
|
||||||
|
this.heartbeats.put(payload.getSender().getProxyId(), payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handleProxyDeath(Death payload) {
|
||||||
|
this.heartbeats.invalidate(payload.getSender().getProxyId());
|
||||||
|
log.info("Proxy {} has disconnected", payload.getSender().getProxyId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int onlinePlayersCount() {
|
||||||
|
// reason we + local online players because our proxy is not inside it own heartbeat cache
|
||||||
|
return heartbeats.asMap().values().stream().mapToInt(Heartbeat::getOnlinePlayersCount).sum()
|
||||||
|
+ platform.localOnlinePlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int onlinePlayersCount(String proxyId) {
|
||||||
|
if (proxyId.equals(this.platform.proxyId())) {
|
||||||
|
return platform.localOnlinePlayers();
|
||||||
|
} else {
|
||||||
|
if (!heartbeats.asMap().containsKey(proxyId)) return 0; // don't error?
|
||||||
|
return heartbeats.asMap().get(proxyId).getOnlinePlayersCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ProxyInfo createProxyInfo() {
|
||||||
|
return ProxyInfo.newBuilder()
|
||||||
|
.setProxyId(platform.proxyId())
|
||||||
|
.setProxyManagerId(this.proxyManagerId.toString())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Death createDeathPayload() {
|
||||||
|
return Death.newBuilder().setSender(createProxyInfo()).setReason(DeathReason.SHUTDOWN).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Heartbeat createHeartbeatPayload() {
|
||||||
|
return Heartbeat.newBuilder()
|
||||||
|
.setSender(createProxyInfo())
|
||||||
|
.setOnlinePlayersCount(platform.localOnlinePlayers())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// return self only if no other proxies
|
||||||
|
public Set<NetworkProxy> getNetworkProxies() {
|
||||||
|
return Stream.concat(
|
||||||
|
this.heartbeats.asMap().values().stream()
|
||||||
|
.map(h -> platform.proxyPlatformCreator(h.getSender().getProxyId())),
|
||||||
|
Stream.of(platform.getLocalProxy()))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<NetworkProxy> getNetworkProxy(String id) {
|
||||||
|
if (platform.networkId().equals(id)) return Optional.of(platform.proxyPlatformCreator(id));
|
||||||
|
if (!this.heartbeats.asMap().containsKey(id)) return Optional.empty();
|
||||||
|
return Optional.of(
|
||||||
|
platform.proxyPlatformCreator(this.heartbeats.asMap().get(id).getSender().getProxyId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void publishDeathPayload();
|
||||||
|
|
||||||
|
protected abstract void publishHeartbeatPayload();
|
||||||
|
|
||||||
|
public abstract void init();
|
||||||
|
|
||||||
|
public abstract void close();
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core;
|
||||||
|
|
||||||
|
import net.limework.valiobungee.api.ValioBungeeAPI;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkProxy;
|
||||||
|
|
||||||
|
public interface ValioBungeePlatform extends ValioBungeeAPI {
|
||||||
|
|
||||||
|
int localOnlinePlayers();
|
||||||
|
|
||||||
|
String platformProxyVendor();
|
||||||
|
|
||||||
|
String networkId();
|
||||||
|
|
||||||
|
String proxyId();
|
||||||
|
|
||||||
|
ProxyNetworkManager proxyNetworkManager();
|
||||||
|
|
||||||
|
PlayerManager playerManager();
|
||||||
|
|
||||||
|
NetworkProxy proxyPlatformCreator(String id);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default String getGitCommit() {
|
||||||
|
return ConstantVariables.GIT_COMMIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default String getVersion() {
|
||||||
|
return ConstantVariables.VERSION;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core.api.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkPlayer;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkProxy;
|
||||||
|
import net.limework.valiobungee.core.ValioBungeePlatform;
|
||||||
|
|
||||||
|
public abstract class AbstractNetworkPlayer implements NetworkPlayer {
|
||||||
|
|
||||||
|
protected final ValioBungeePlatform platform;
|
||||||
|
protected final UUID uuid;
|
||||||
|
protected final NetworkProxy proxy;
|
||||||
|
|
||||||
|
public AbstractNetworkPlayer(ValioBungeePlatform platform, UUID uuid, NetworkProxy proxy) {
|
||||||
|
this.platform = platform;
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.proxy = proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() {
|
||||||
|
return this.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkProxy getProxy() {
|
||||||
|
return this.proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof AbstractNetworkPlayer that)) return false;
|
||||||
|
return Objects.equals(uuid, that.uuid) && Objects.equals(proxy, that.proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(uuid, proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core.api.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkProxy;
|
||||||
|
import net.limework.valiobungee.core.ValioBungeePlatform;
|
||||||
|
|
||||||
|
public abstract class AbstractNetworkProxy implements NetworkProxy {
|
||||||
|
|
||||||
|
private final ValioBungeePlatform platform;
|
||||||
|
|
||||||
|
private final String proxyId;
|
||||||
|
|
||||||
|
public AbstractNetworkProxy(ValioBungeePlatform platform, String proxyId) {
|
||||||
|
this.platform = platform;
|
||||||
|
this.proxyId = proxyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String proxyId() {
|
||||||
|
return this.proxyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int onlinePlayerCount() {
|
||||||
|
return this.platform.proxyNetworkManager().onlinePlayersCount(this.proxyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMe() {
|
||||||
|
return this.platform.proxyId().equals(proxyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof AbstractNetworkProxy that)) return false;
|
||||||
|
return Objects.equals(proxyId, that.proxyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(proxyId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core.util.logging;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
public class LogProviderFactory {
|
||||||
|
private static Logger instance;
|
||||||
|
|
||||||
|
public static void register(Logger logger) {
|
||||||
|
if (instance != null) throw new IllegalStateException("Logger already registered");
|
||||||
|
instance = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger get() {
|
||||||
|
if (instance == null) throw new IllegalStateException("No logger registered");
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
core/src/main/proto/message-protocol.proto
Normal file
28
core/src/main/proto/message-protocol.proto
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package net.limework.valiobungee.core.proto.messages;
|
||||||
|
option java_multiple_files = true;
|
||||||
|
|
||||||
|
message ProxyInfo {
|
||||||
|
string proxy_id = 1; // UNIQUE ID
|
||||||
|
string proxy_manager_id = 2; // ProxyManager id. changes every reboot, used to detect duplicate proxy names
|
||||||
|
}
|
||||||
|
|
||||||
|
// heartbeat ._.?
|
||||||
|
|
||||||
|
message Heartbeat {
|
||||||
|
ProxyInfo sender = 1;
|
||||||
|
int32 online_players_count = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// death
|
||||||
|
enum DeathReason {
|
||||||
|
UNSPECIFIED = 0; // TESTING ONLY
|
||||||
|
RELOAD = 1; // plugin reload
|
||||||
|
SHUTDOWN = 2; // proxy shutdown
|
||||||
|
}
|
||||||
|
message Death {
|
||||||
|
ProxyInfo sender = 1; // proxy that died
|
||||||
|
DeathReason reason = 2;
|
||||||
|
}
|
||||||
|
|
||||||
9
core/standalone/build.gradle.kts
Normal file
9
core/standalone/build.gradle.kts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
dependencies {
|
||||||
|
compileOnly(project(":valiobungee-core"))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
description = "ValioBungee standalone `offline` implementation"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import net.limework.valiobungee.api.entity.NetworkPlayer;
|
||||||
|
|
||||||
|
public class StandalonePlayerManager extends PlayerManager {
|
||||||
|
|
||||||
|
public StandalonePlayerManager(ValioBungeePlatform platform) {
|
||||||
|
super(platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<NetworkPlayer> getNetworkPlayer(UUID uuid) {
|
||||||
|
return platform.getLocalProxyPlayers().stream()
|
||||||
|
.filter(p -> p.getUniqueId().equals(uuid))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<NetworkPlayer> getNetworkPlayers() {
|
||||||
|
return platform.getLocalProxyPlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOnline(UUID uuid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleJoin(UUID uuid) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleQuit(UUID uuid) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void correctionTask() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 ValioBungee contributors
|
||||||
|
*
|
||||||
|
* This file is part of ValioBungee.
|
||||||
|
*
|
||||||
|
* ValioBungee is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ValioBungee 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 ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
package net.limework.valiobungee.core;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import net.limework.valiobungee.core.proto.messages.Death;
|
||||||
|
import net.limework.valiobungee.core.proto.messages.DeathReason;
|
||||||
|
import net.limework.valiobungee.core.proto.messages.Heartbeat;
|
||||||
|
import net.limework.valiobungee.core.proto.messages.ProxyInfo;
|
||||||
|
|
||||||
|
/** this class is used to debug the abstract class */
|
||||||
|
public class StandaloneProxyNetworkManager extends ProxyNetworkManager {
|
||||||
|
public StandaloneProxyNetworkManager(ValioBungeePlatform platform) {
|
||||||
|
super(platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void publishDeathPayload() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void publishHeartbeatPayload() {}
|
||||||
|
|
||||||
|
private final AtomicBoolean shutdown = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
private void makeFakeProxiesRunning() {
|
||||||
|
// fake 12 proxies
|
||||||
|
String fakePrefix = "fake-proxy-";
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
String prefix = fakePrefix + i;
|
||||||
|
Heartbeat heartbeat =
|
||||||
|
Heartbeat.newBuilder()
|
||||||
|
.setSender(ProxyInfo.newBuilder().setProxyId(prefix).build())
|
||||||
|
.setOnlinePlayersCount(i)
|
||||||
|
.build();
|
||||||
|
Thread.ofVirtual()
|
||||||
|
.start(
|
||||||
|
() -> {
|
||||||
|
while (!shutdown.get()) {
|
||||||
|
handleProxyHeartBeat(heartbeat);
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handleProxyDeath(
|
||||||
|
Death.newBuilder()
|
||||||
|
.setReason(DeathReason.SHUTDOWN)
|
||||||
|
.setSender(heartbeat.getSender())
|
||||||
|
.build());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeFakeProxiesDisappearing() {
|
||||||
|
// fake 12 proxies
|
||||||
|
String fakePrefix = "fake-disappear-proxy-";
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
String prefix = fakePrefix + i;
|
||||||
|
Heartbeat heartbeat =
|
||||||
|
Heartbeat.newBuilder()
|
||||||
|
.setSender(ProxyInfo.newBuilder().setProxyId(prefix).build())
|
||||||
|
.setOnlinePlayersCount(i)
|
||||||
|
.build();
|
||||||
|
handleProxyHeartBeat(heartbeat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeFakeProxiesShuttingDown() {
|
||||||
|
// fake 12 proxies
|
||||||
|
String fakePrefix = "fake-shutdown-proxy-";
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
String prefix = fakePrefix + i;
|
||||||
|
Heartbeat heartbeat =
|
||||||
|
Heartbeat.newBuilder()
|
||||||
|
.setSender(ProxyInfo.newBuilder().setProxyId(prefix).build())
|
||||||
|
.setOnlinePlayersCount(i)
|
||||||
|
.build();
|
||||||
|
Thread.ofVirtual()
|
||||||
|
.start(
|
||||||
|
() -> {
|
||||||
|
int li = 0;
|
||||||
|
int liMax = 60 + ThreadLocalRandom.current().nextInt(20);
|
||||||
|
while (!shutdown.get() && li <= liMax) {
|
||||||
|
handleProxyHeartBeat(heartbeat);
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
li++;
|
||||||
|
}
|
||||||
|
handleProxyDeath(
|
||||||
|
Death.newBuilder()
|
||||||
|
.setReason(DeathReason.SHUTDOWN)
|
||||||
|
.setSender(heartbeat.getSender())
|
||||||
|
.build());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
makeFakeProxiesRunning();
|
||||||
|
makeFakeProxiesDisappearing();
|
||||||
|
makeFakeProxiesShuttingDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
shutdown.set(true);
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
gradle.properties
Normal file
5
gradle.properties
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
group=net.limework
|
||||||
|
version=1.0.0-SNAPSHOT
|
||||||
|
|
||||||
|
redisbungee-group=com.imaginarycode.minecraft
|
||||||
|
redisbungee-version=0.13.0-SNAPSHOT
|
||||||
53
gradle/libs.versions.toml
Normal file
53
gradle/libs.versions.toml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
[versions]
|
||||||
|
protobuf-plugin = "0.9.5"
|
||||||
|
protobuf = "3.25.8" # needed for reference to be used for protoc
|
||||||
|
slf4j = "2.0.17"
|
||||||
|
|
||||||
|
guava = "33.5.0-jre"
|
||||||
|
jedis = "5.2.0"
|
||||||
|
okhttp = "4.12.0"
|
||||||
|
configurateV3 = "3.7.3"
|
||||||
|
adventure = "4.26.1"
|
||||||
|
adventure-bungeecord-platform = "4.4.1"
|
||||||
|
acf = "e2005dd62d"
|
||||||
|
bungeecordApi = "1.21-R0.5-SNAPSHOT"
|
||||||
|
velocity = "3.5.0-SNAPSHOT"
|
||||||
|
|
||||||
|
[plugins]
|
||||||
|
blossom = "net.kyori.blossom:2.2.0"
|
||||||
|
indragit = "net.kyori.indra.git:4.0.0"
|
||||||
|
shadow = "com.gradleup.shadow:9.3.1"
|
||||||
|
spotless = "com.diffplug.spotless:8.2.0"
|
||||||
|
protobuf = { id = "com.google.protobuf", version.ref = "protobuf-plugin" }
|
||||||
|
run-velocity = { id = "xyz.jpenilla.run-velocity", version = "3.0.2" }
|
||||||
|
|
||||||
|
[libraries]
|
||||||
|
# protobuf
|
||||||
|
protobuf = { group = "com.google.protobuf", name = "protobuf-java", version.ref = "protobuf" }
|
||||||
|
protoc = { group = "com.google.protobuf", name = "protoc", version.ref = "protobuf" }
|
||||||
|
|
||||||
|
# valiobungee
|
||||||
|
redisson = "org.redisson:redisson:4.3.0"
|
||||||
|
caffeine = "com.github.ben-manes.caffeine:caffeine:3.2.3"
|
||||||
|
# logging
|
||||||
|
slf4j = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
|
||||||
|
|
||||||
|
# testing
|
||||||
|
testing-juipter = "org.junit.jupiter:junit-jupiter:6.0.3"
|
||||||
|
testing-slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
|
||||||
|
|
||||||
|
# redisbungee speific
|
||||||
|
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
||||||
|
jedis = { module = "redis.clients:jedis", version.ref = "jedis" }
|
||||||
|
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
|
||||||
|
configurateV3 = { module = "org.spongepowered:configurate-yaml", version.ref = "configurateV3" }
|
||||||
|
|
||||||
|
# minecraft speific
|
||||||
|
adventure-api = { module = "net.kyori:adventure-api", version.ref = "adventure" }
|
||||||
|
adventure-miniMessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "adventure" }
|
||||||
|
acf-core = { module = "com.github.ProxioDev.commands:acf-core", version.ref = "acf" }
|
||||||
|
acf-bungeecord = { module = "com.github.ProxioDev.commands:acf-bungee", version.ref = "acf" }
|
||||||
|
acf-velocity = { module = "com.github.ProxioDev.commands:acf-velocity", version.ref = "acf" }
|
||||||
|
platform-bungeecord = { module = "net.md-5:bungeecord-api", version.ref = "bungeecordApi" }
|
||||||
|
adventure-platforms-bungeecord = { module = "net.kyori:adventure-platform-bungeecord", version.ref = "adventure-bungeecord-platform" }
|
||||||
|
platform-velocity = { module = "com.velocitypowered:velocity-api", version.ref = "velocity" }
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user