mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-05-03 03:30:26 +00:00
Compare commits
190 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
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 | ||
| 0f0f707ef7 | |||
| 441a12bb36 | |||
|
|
0534970368 | ||
| 20f9143ea5 | |||
| 1a2459b64e | |||
|
|
c3888c8f65 | ||
| c8362a44ec | |||
| 31e461a11c | |||
| a9ea04c2c0 | |||
| ddfc689c2d | |||
| ae6961ef24 | |||
| 8318bcd1bf | |||
| 0b9fd6d7ff | |||
| a526298d1c | |||
| c69b1e214e | |||
| e5f0075a58 | |||
| 748bc13568 | |||
| 5e3ce725de | |||
| 92bb0030de | |||
| d8c21edc7a | |||
| 87a2b93537 | |||
| 0f5d5b2440 | |||
| 21f543581c | |||
| bc266ae1fa | |||
| 8dc42d071a | |||
| 71b959936e | |||
| 28419b3168 | |||
| a382a298a1 | |||
| 4d58ee1742 | |||
| af4e180b2c | |||
| c1ad902bd3 | |||
| 74ed18e9b3 | |||
| a51ff98909 | |||
| 80a4791d12 | |||
| fdd537b276 | |||
| 17897bc112 | |||
| 576bcc39d2 | |||
| 508125023e | |||
| 43b2d20e39 | |||
| 64af12044e | |||
| 2ae9b5d480 | |||
| d77e909e7d | |||
| ee76fa0b3d | |||
|
|
f303f2c202 | ||
|
|
4e46dc5536 | ||
|
|
b58e503ec7 | ||
|
|
b16a7d4cbc | ||
| 5a7001a68c | |||
| 81a8fd218e | |||
| 92f5e04edf | |||
| e7b241edd6 | |||
| 86c6e9464d | |||
| 1828cd854c | |||
| 6910c96f67 | |||
| 8f602407b5 | |||
| 2c4fc00ec3 | |||
| 11e867730c | |||
| 830077282d | |||
| 2b2ae88587 | |||
| 9ceccb6dd2 | |||
| dea384a203 | |||
| e4012a8d7b | |||
| 2c8c5fc1cf | |||
| 5c6cf405fa | |||
| 0408e2923b | |||
| 5d1167c20f | |||
| 79694fcbb2 | |||
| 1d889f28b9 | |||
| f274301036 | |||
| c787c76eca | |||
| 9da5845da3 | |||
| 4d3f1a551e | |||
| 17e6e12c24 | |||
| c207b4a0a2 | |||
| c848126aa7 | |||
| f722b8c9d3 | |||
| d806bc2d41 | |||
| 2e8342f5c3 | |||
|
|
c125137a74 | ||
| aff185a85b | |||
| 482dfc5141 | |||
| 6a6e303334 | |||
| a9600a7d8a | |||
| 36136d0c0f | |||
| 319b5eb553 | |||
| 38de948c6b | |||
| 019bb30c09 | |||
| f1f74b6456 | |||
| b0ab5e3cb4 | |||
| b214e3dad7 | |||
| 81a2af8179 | |||
| b910fa5eb6 | |||
| b15b9dbb96 | |||
| 44f9a0945d | |||
| e986d5f1fb | |||
| ce93bd5e07 | |||
| 870e6113db | |||
| 86b0904546 | |||
| f4dbb00991 | |||
| b6e4badc05 | |||
| 78ae6ff7b6 | |||
| 87aaf22073 | |||
| a74e4b6a15 | |||
| d6d8c30343 | |||
| 933fceba9d | |||
| a8b369dde3 | |||
| 414f29e99c | |||
|
|
21f6cdeaeb | ||
| 5f07ba6b66 | |||
| 673b966dda | |||
| 69d435d455 | |||
| 3a8baae56f | |||
| 803ae36d00 | |||
| ceef1f5184 | |||
| cd4f2aded4 | |||
| d8a220bcc2 | |||
|
|
c3d23a3601 | ||
|
|
ea600c5b44 | ||
| 86f2d89cf4 | |||
| 70d1aadd56 | |||
| 183c227b77 | |||
| 640b26067a | |||
| 660bb239bb | |||
| dd9c9e368d | |||
| 76787455d8 | |||
| 2c11cb179a | |||
| 9f05bd3438 | |||
|
|
c04a911fbe | ||
| 0311a893c7 | |||
| 5a51d5c1b3 | |||
| afac7a3d51 | |||
| bdda99bc81 | |||
| ea665fd70f | |||
| f7285ff4f1 | |||
|
|
28d1667fe9 | ||
|
|
839c8cd615 | ||
|
|
83dff6b280 | ||
|
|
0b868ffd6f | ||
|
|
d7c8544b99 | ||
| 2391692dd3 | |||
| 39c45b3eab | |||
| b3bc51b96f | |||
| 08c4901f47 | |||
| a39c4654fb | |||
| 2ceac5a079 | |||
| 814dabbb6a | |||
|
|
1a76c260b8 | ||
| 24c9407358 | |||
| eee36923c1 | |||
| 6e02ab70db | |||
|
|
9493576067 | ||
|
|
02c9c3c75a | ||
|
|
0326c4490a | ||
| d34db3da44 | |||
| 5e18c4adb5 | |||
| ade1604987 | |||
| 7b2db2899e |
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
|
||||
42
.github/workflows/gradle.yml
vendored
Normal file
42
.github/workflows/gradle.yml
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
# This workflow will build a Java project with Maven
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: RedisBungee Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'adopt'
|
||||
- name: Build with gradle
|
||||
run: ./gradlew shadowJar
|
||||
- name: Upload Bungee
|
||||
uses: actions/upload-artifact@v2.2.3
|
||||
with:
|
||||
# Artifact name
|
||||
name: RedisBungee-Bungee
|
||||
# Destination path
|
||||
path: RedisBungee-Bungee/build/libs/*
|
||||
- name: Upload Velocity
|
||||
uses: actions/upload-artifact@v2.2.3
|
||||
with:
|
||||
name: RedisBungee-Velocity
|
||||
path: RedisBungee-Velocity/build/libs/*
|
||||
- name: Upload API
|
||||
uses: actions/upload-artifact@v2.2.3
|
||||
with:
|
||||
name: RedisBungee-API
|
||||
path: RedisBungee-API/build/libs/*
|
||||
32
.github/workflows/maven.yml
vendored
32
.github/workflows/maven.yml
vendored
@@ -1,32 +0,0 @@
|
||||
# This workflow will build a Java project with Maven
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: RedisBungee Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
- name: Download a Build Artifact
|
||||
uses: actions/upload-artifact@v2.2.3
|
||||
with:
|
||||
# Artifact name
|
||||
name: Redis_JAR
|
||||
# Destination path
|
||||
path: target/RedisBungee*
|
||||
15
.gitignore
vendored
15
.gitignore
vendored
@@ -3,6 +3,10 @@
|
||||
.project
|
||||
.settings
|
||||
|
||||
# random files
|
||||
.png
|
||||
.jpg
|
||||
|
||||
# netbeans
|
||||
nbproject
|
||||
nbactions.xml
|
||||
@@ -32,5 +36,14 @@ manifest.mf
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
|
||||
*.versionBackup
|
||||
*.versionsBackup
|
||||
# gradle
|
||||
.gradle
|
||||
|
||||
# java docs
|
||||
javadoc
|
||||
javadoc
|
||||
|
||||
# run-server folders
|
||||
*/run
|
||||
|
||||
76
README.md
76
README.md
@@ -1,75 +1,29 @@
|
||||
# RedisBungee By Limework
|
||||
# RedisBungee Limework's Fork
|
||||
|
||||
[](https://github.com/Limework/RedisBungee/actions/workflows/maven.yml) [](https://jitpack.io/#limework/redisbungee)
|
||||
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/)
|
||||
to Synchronize players data between [BungeeCord](https://github.com/SpigotMC/BungeeCord)
|
||||
or [Velocity*](https://github.com/PaperMC/Velocity) proxies
|
||||
|
||||
Spigot link: [click](https://www.spigotmc.org/resources/redisbungee.87700/)
|
||||
## Downloads
|
||||
|
||||
The main project of RedisBungee is no longer maintained, so we have forked the plugin.
|
||||
[](https://modrinth.com/plugin/redisbungee)
|
||||
|
||||
RedisBungee uses [Redis](https://redis.io) to Synchronize data between [BungeeCord](https://github.com/SpigotMC/BungeeCord) proxies
|
||||
## Wiki
|
||||
|
||||
## Notice 1: about older versions of redis than redis 6.0
|
||||
https://github.com/ProxioDev/RedisBungee/wiki
|
||||
|
||||
any versions of redis-bungee 0.6.4 or above only supports 6.0
|
||||
Do not Open issues regarding it.
|
||||
## Support
|
||||
|
||||
## Notice 2: users on git.limework.net
|
||||
open an issue with question button
|
||||
|
||||
please create the issues on GitHub as its main project source.
|
||||
|
||||
## Compiling
|
||||
RedisBungee is distributed as a [maven](https://maven.apache.org) project.
|
||||
|
||||
first, install it to your maven local repo as we don't have public maven repo.
|
||||
```
|
||||
git clone https://github.com/ProxioDev/RedisBungee.git
|
||||
cd RedisBungee
|
||||
mvn clean install
|
||||
```
|
||||
If you want to have `RedisBungeeAPI` class
|
||||
```
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee-API</artifactId>
|
||||
<version>0.7.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
and if you want to use the events Import RedisBungee-BungeeEvents which for bungeecord
|
||||
`note: you need API imported too`
|
||||
```
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee-BungeeEvents</artifactId>
|
||||
<version>0.7.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
## Javadocs
|
||||
Check out our Java docs on github pages
|
||||
https://proxiodev.github.io/RedisBungee-JavaDocs/0.7.0-SNAPSHOT
|
||||
|
||||
## Configuration
|
||||
|
||||
**REDISBUNGEE REQUIRES A REDIS SERVER**, preferably with reasonably low latency. The default [config](https://github.com/proxiodev/RedisBungee/blob/master/src/main/resources/example_config.yml) is saved when the plugin first starts.
|
||||
|
||||
## License!
|
||||
## 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 by minecrafter [here](https://github.com/minecrafter/RedisBungee) or spigot page [here](https://www.spigotmc.org/resources/redisbungee.13494/)
|
||||
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/)
|
||||
|
||||
## Support
|
||||
|
||||
You can join our matrix room [here](https://matrix.to/#/!zhedzmRNSZXfuOPZUB:govindas.net?via=govindas.net&via=matrix.org)
|
||||
|
||||

|
||||
|
||||
|
||||
## YourKit
|
||||
|
||||
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/).
|
||||
|
||||

|
||||
|
||||
85
RedisBungee-API/build.gradle.kts
Normal file
85
RedisBungee-API/build.gradle.kts
Normal file
@@ -0,0 +1,85 @@
|
||||
import java.time.Instant
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
id("net.kyori.blossom") version "1.2.0"
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(libs.guava)
|
||||
api(libs.jedis)
|
||||
api(libs.okhttp)
|
||||
api(libs.configurate)
|
||||
api(libs.caffeine)
|
||||
api(libs.adventure.api)
|
||||
api(libs.adventure.gson)
|
||||
api(libs.adventure.legacy)
|
||||
api(libs.adventure.plain)
|
||||
api(libs.adventure.miniMessage)
|
||||
}
|
||||
|
||||
description = "RedisBungee interfaces"
|
||||
|
||||
blossom {
|
||||
replaceToken("@version@", "$version")
|
||||
// GIT
|
||||
val commit: String;
|
||||
val commitStdout = ByteArrayOutputStream()
|
||||
rootProject.exec {
|
||||
standardOutput = commitStdout
|
||||
commandLine("git", "rev-parse", "HEAD")
|
||||
}
|
||||
commit = "$commitStdout".replace("\n", "") // for some reason it adds new line so remove it.
|
||||
commitStdout.close()
|
||||
replaceToken("@git_commit@", commit)
|
||||
}
|
||||
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
tasks {
|
||||
// thanks again for paper too
|
||||
withType<Javadoc> {
|
||||
val options = options as StandardJavadocDocletOptions
|
||||
options.use()
|
||||
options.isDocFilesSubDirs = true
|
||||
val jedisVersion = libs.jedis.get().version
|
||||
val configurateVersion = libs.configurate.get().version
|
||||
val guavaVersion = libs.guava.get().version
|
||||
val adventureVersion = libs.adventure.plain.get().version
|
||||
options.links(
|
||||
"https://configurate.aoeu.xyz/$configurateVersion/apidocs/", // configurate
|
||||
"https://javadoc.io/doc/redis.clients/jedis/$jedisVersion/", // jedis
|
||||
"https://guava.dev/releases/$guavaVersion/api/docs/", // guava
|
||||
"https://javadoc.io/doc/com.github.ben-manes.caffeine/caffeine",
|
||||
"https://jd.advntr.dev/api/$adventureVersion"
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.release.set(17)
|
||||
}
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
processResources {
|
||||
filteringCharset = Charsets.UTF_8.name()
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,124 +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.7.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>RedisBungee-API</artifactId>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<reportOutputDirectory>../javadoc</reportOutputDirectory>
|
||||
<destDir>${project.name}</destDir>
|
||||
</configuration>
|
||||
</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>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<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.2.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>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -1,39 +1,51 @@
|
||||
/*
|
||||
* 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.internal.RedisBungeePlugin;
|
||||
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 net.kyori.adventure.text.Component;
|
||||
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 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#getApi()}.
|
||||
*
|
||||
* @author tuxed
|
||||
* @since 0.2.3 | updated 0.7.0
|
||||
* 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 class RedisBungeeAPI {
|
||||
private final RedisBungeePlugin<?> plugin;
|
||||
private final List<String> reservedChannels;
|
||||
private static RedisBungeeAPI redisBungeeApi;
|
||||
public abstract class AbstractRedisBungeeAPI {
|
||||
protected final RedisBungeePlugin<?> plugin;
|
||||
private static AbstractRedisBungeeAPI abstractRedisBungeeAPI;
|
||||
|
||||
RedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
||||
public AbstractRedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
||||
// this does make sure that no one can replace first initiated API class.
|
||||
if (abstractRedisBungeeAPI == null) {
|
||||
abstractRedisBungeeAPI = this;
|
||||
}
|
||||
this.plugin = plugin;
|
||||
redisBungeeApi = this;
|
||||
this.reservedChannels = ImmutableList.of(
|
||||
"redisbungee-allservers",
|
||||
"redisbungee-" + plugin.getConfiguration().getServerId(),
|
||||
"redisbungee-data"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +54,7 @@ public class RedisBungeeAPI {
|
||||
* @return a count of all players found
|
||||
*/
|
||||
public final int getPlayerCount() {
|
||||
return plugin.getCount();
|
||||
return plugin.proxyDataManager().totalNetworkPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,18 +65,19 @@ public class RedisBungeeAPI {
|
||||
* @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);
|
||||
return plugin.playerDataManager().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 name
|
||||
* @return a String name for the server the player is on.
|
||||
* @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
|
||||
*/
|
||||
public final String getServerFor(@NonNull UUID player) {
|
||||
return plugin.getDataManager().getServer(player);
|
||||
@Nullable
|
||||
public final String getServerNameFor(@NonNull UUID player) {
|
||||
return plugin.playerDataManager().getServerFor(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +88,7 @@ public class RedisBungeeAPI {
|
||||
* @return a Set with all players found
|
||||
*/
|
||||
public final Set<UUID> getPlayersOnline() {
|
||||
return plugin.getPlayers();
|
||||
return plugin.proxyDataManager().networkPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,11 +109,11 @@ public class RedisBungeeAPI {
|
||||
/**
|
||||
* Get a full list of players on all servers.
|
||||
*
|
||||
* @return a immutable Multimap with all players found on this server
|
||||
* @return a immutable Multimap with all players found on this network
|
||||
* @since 0.2.5
|
||||
*/
|
||||
public final Multimap<String, UUID> getServerToPlayers() {
|
||||
return plugin.serversToPlayers();
|
||||
return plugin.playerDataManager().serversToPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,11 +129,11 @@ public class RedisBungeeAPI {
|
||||
/**
|
||||
* Get a list of players on the specified proxy.
|
||||
*
|
||||
* @param server a server name
|
||||
* @param proxyID proxy id
|
||||
* @return a Set with all UUIDs found on this proxy
|
||||
*/
|
||||
public final Set<UUID> getPlayersOnProxy(@NonNull String server) {
|
||||
return plugin.getPlayersOnProxy(server);
|
||||
public final Set<UUID> getPlayersOnProxy(@NonNull String proxyID) {
|
||||
return plugin.proxyDataManager().getPlayersOn(proxyID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +154,7 @@ public class RedisBungeeAPI {
|
||||
* @since 0.2.4
|
||||
*/
|
||||
public final InetAddress getPlayerIp(@NonNull UUID player) {
|
||||
return plugin.getDataManager().getIp(player);
|
||||
return plugin.playerDataManager().getIpFor(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +165,7 @@ public class RedisBungeeAPI {
|
||||
* @since 0.3.3
|
||||
*/
|
||||
public final String getProxy(@NonNull UUID player) {
|
||||
return plugin.getDataManager().getProxy(player);
|
||||
return plugin.playerDataManager().getProxyFor(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +176,7 @@ public class RedisBungeeAPI {
|
||||
* @since 0.2.5
|
||||
*/
|
||||
public final void sendProxyCommand(@NonNull String command) {
|
||||
plugin.sendProxyCommand("allservers", command);
|
||||
sendProxyCommand("allservers", command);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,35 +184,60 @@ public class RedisBungeeAPI {
|
||||
*
|
||||
* @param proxyId a proxy ID
|
||||
* @param command the command to send and execute
|
||||
* @see #getServerId()
|
||||
* @see #getAllServers()
|
||||
* @see #getProxyId()
|
||||
* @see #getAllProxies()
|
||||
* @since 0.2.5
|
||||
*/
|
||||
public final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
|
||||
plugin.sendProxyCommand(proxyId, command);
|
||||
plugin.proxyDataManager().sendCommandTo(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.
|
||||
* Sends a message to a PubSub channel which makes PubSubMessageEvent fire.
|
||||
* <p>
|
||||
* Note: Since 0.12.0 registering a channel api is no longer required
|
||||
*
|
||||
* @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);
|
||||
plugin.proxyDataManager().sendChannelMessage(channel, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current BungeeCord server ID for this server.
|
||||
* 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.proxyDataManager().proxyId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 plugin.getConfiguration().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.proxyDataManager().proxiesIds();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,9 +246,11 @@ public class RedisBungeeAPI {
|
||||
* @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 plugin.getServerIds();
|
||||
return getAllProxies();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,9 +258,10 @@ public class RedisBungeeAPI {
|
||||
*
|
||||
* @param channels the channels to register
|
||||
* @since 0.3
|
||||
* @deprecated No longer required
|
||||
*/
|
||||
@Deprecated
|
||||
public final void registerPubSubChannels(String... channels) {
|
||||
plugin.getPubSubListener().addChannel(channels);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,13 +269,10 @@ public class RedisBungeeAPI {
|
||||
*
|
||||
* @param channels the channels to unregister
|
||||
* @since 0.3
|
||||
* @deprecated No longer required
|
||||
*/
|
||||
@Deprecated
|
||||
public final void unregisterPubSubChannels(String... channels) {
|
||||
for (String channel : channels) {
|
||||
Preconditions.checkArgument(!reservedChannels.contains(channel), "attempting to unregister internal channel");
|
||||
}
|
||||
|
||||
plugin.getPubSubListener().removeChannel(channels);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,35 +343,149 @@ public class RedisBungeeAPI {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This gets Redis Bungee {@link JedisPool}
|
||||
* @return {@link JedisPool}
|
||||
* @deprecated this secluded to be removed when support for redis sentinel or redis cluster is finished, use {@link RedisBungeeAPI#requestJedis()}
|
||||
* @since 0.6.5
|
||||
* Kicks a player from the network
|
||||
* calls {@link #getUuidFromName(String)} to get uuid
|
||||
*
|
||||
* @param playerName player name
|
||||
* @param message kick message that player will see on kick
|
||||
* @since 0.8.0
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public JedisPool getJedisPool() {
|
||||
return this.plugin.getJedisPool();
|
||||
public void kickPlayer(String playerName, String message) {
|
||||
kickPlayer(getUuidFromName(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
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void kickPlayer(UUID playerUUID, String message) {
|
||||
kickPlayer(playerUUID, Component.text(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks a player from the network
|
||||
* calls {@link #getUuidFromName(String)} to get uuid
|
||||
*
|
||||
* @param playerName player name
|
||||
* @param message kick message that player will see on kick
|
||||
* @since 0.12.0
|
||||
*/
|
||||
|
||||
public void kickPlayer(String playerName, Component message) {
|
||||
kickPlayer(getUuidFromName(playerName), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks a player from the network
|
||||
*
|
||||
* @param playerUUID player name
|
||||
* @param message kick message that player will see on kick
|
||||
* @since 0.12.0
|
||||
*/
|
||||
public void kickPlayer(UUID playerUUID, Component message) {
|
||||
this.plugin.playerDataManager().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() {
|
||||
return this.plugin.requestJedis();
|
||||
if (getMode() == RedisBungeeMode.SINGLE) {
|
||||
return getJedisPool().getResource();
|
||||
} else {
|
||||
throw new IllegalStateException("Mode is not " + RedisBungeeMode.SINGLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets Redis Bungee {@link JedisPool}
|
||||
*
|
||||
* @return the API instance.
|
||||
* @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 static RedisBungeeAPI getRedisBungeeApi() {
|
||||
return redisBungeeApi;
|
||||
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
|
||||
* Basically what every redis mode is used like cluster or single instance.
|
||||
*
|
||||
* @return {@link RedisBungeeMode}
|
||||
* @since 0.8.0
|
||||
*/
|
||||
public RedisBungeeMode getMode() {
|
||||
return this.plugin.getRedisBungeeMode();
|
||||
}
|
||||
|
||||
public static AbstractRedisBungeeAPI getAbstractRedisBungeeAPI() {
|
||||
return abstractRedisBungeeAPI;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 Constants {
|
||||
|
||||
public final static String VERSION = "@version@";
|
||||
public final static String GIT_COMMIT = "@git_commit@";
|
||||
|
||||
public static String getGithubCommitLink() {
|
||||
return "https://github.com/ProxioDev/RedisBungee/commit/" + GIT_COMMIT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
/**
|
||||
* This used to be old plugin instance of redis-bungee, but now it's used to get the api for old plugins
|
||||
*
|
||||
* @deprecated its deprecated but won't be removed, so please use {@link RedisBungeeAPI#getRedisBungeeApi()}
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class RedisBungee {
|
||||
|
||||
private static RedisBungeeAPI api;
|
||||
|
||||
public RedisBungee(RedisBungeeAPI api) {
|
||||
RedisBungee.api = api;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 RedisBungeeAPI} object instance.
|
||||
*/
|
||||
@Deprecated
|
||||
public static RedisBungeeAPI getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* 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.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisPipelineTask;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
|
||||
import org.json.JSONObject;
|
||||
import redis.clients.jedis.ClusterPipeline;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEvent, SC extends IPlayerChangedServerNetworkEvent, NJE extends IPlayerLeftNetworkEvent, CE> {
|
||||
|
||||
protected final RedisBungeePlugin<P> plugin;
|
||||
private final LoadingCache<UUID, String> serverCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getServerFromRedis);
|
||||
private final LoadingCache<UUID, String> lastServerCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getLastServerFromRedis);
|
||||
private final LoadingCache<UUID, String> proxyCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getProxyFromRedis);
|
||||
private final LoadingCache<UUID, InetAddress> ipCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getIpAddressFromRedis);
|
||||
private final LoadingCache<UUID, Long> lastOnlineCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getLastOnlineFromRedis);
|
||||
private final Object SERVERS_TO_PLAYERS_KEY = new Object();
|
||||
private final LoadingCache<Object, Multimap<String, UUID>> serverToPlayersCache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build(this::serversToPlayersBuilder);
|
||||
private final UnifiedJedis unifiedJedis;
|
||||
private final String proxyId;
|
||||
private final String networkId;
|
||||
|
||||
public PlayerDataManager(RedisBungeePlugin<P> plugin) {
|
||||
this.plugin = plugin;
|
||||
this.unifiedJedis = plugin.proxyDataManager().unifiedJedis();
|
||||
this.proxyId = plugin.proxyDataManager().proxyId();
|
||||
this.networkId = plugin.proxyDataManager().networkId();
|
||||
}
|
||||
|
||||
// handle network wide
|
||||
// server change
|
||||
public abstract void onPlayerChangedServerNetworkEvent(SC event);
|
||||
|
||||
public abstract void onNetworkPlayerQuit(NJE event);
|
||||
|
||||
// local events
|
||||
public abstract void onPubSubMessageEvent(PS event);
|
||||
|
||||
public abstract void onServerConnectedEvent(CE event);
|
||||
|
||||
public abstract void onLoginEvent(LE event);
|
||||
|
||||
public abstract void onDisconnectEvent(DE event);
|
||||
|
||||
|
||||
protected void handleNetworkPlayerServerChange(IPlayerChangedServerNetworkEvent event) {
|
||||
this.serverCache.invalidate(event.getUuid());
|
||||
this.lastServerCache.invalidate(event.getUuid());
|
||||
}
|
||||
|
||||
protected void handleNetworkPlayerQuit(IPlayerLeftNetworkEvent event) {
|
||||
this.proxyCache.invalidate(event.getUuid());
|
||||
this.serverCache.invalidate(event.getUuid());
|
||||
this.ipCache.invalidate(event.getUuid());
|
||||
this.lastOnlineCache.invalidate(event.getUuid());
|
||||
}
|
||||
|
||||
protected void handlePubSubMessageEvent(IPubSubMessageEvent event) {
|
||||
// kick api
|
||||
if (event.getChannel().equals("redisbungee-kick")) {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
String proxy = data.getString("proxy");
|
||||
if (proxy.equals(this.proxyId)) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
String message = data.getString("message");
|
||||
plugin.handlePlatformKick(uuid, COMPONENT_SERIALIZER.deserialize(message));
|
||||
return;
|
||||
}
|
||||
if (event.getChannel().equals("redisbungee-serverchange")) {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
String proxy = data.getString("proxy");
|
||||
if (proxy.equals(this.proxyId)) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
String from = null;
|
||||
if (data.has("from")) from = data.getString("from");
|
||||
String to = data.getString("to");
|
||||
plugin.fireEvent(plugin.createPlayerChangedServerNetworkEvent(uuid, from, to));
|
||||
return;
|
||||
}
|
||||
if (event.getChannel().equals("redisbungee-player-join")) {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
String proxy = data.getString("proxy");
|
||||
if (proxy.equals(this.proxyId)) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
plugin.fireEvent(plugin.createPlayerJoinedNetworkEvent(uuid));
|
||||
return;
|
||||
}
|
||||
if (event.getChannel().equals("redisbungee-player-leave")) {
|
||||
JSONObject data = new JSONObject(event.getMessage());
|
||||
String proxy = data.getString("proxy");
|
||||
if (proxy.equals(this.proxyId)) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||
plugin.fireEvent(plugin.createPlayerLeftNetworkEvent(uuid));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void playerChangedServer(UUID uuid, String from, String to) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("proxy", this.proxyId);
|
||||
data.put("uuid", uuid);
|
||||
data.put("from", from);
|
||||
data.put("to", to);
|
||||
plugin.proxyDataManager().sendChannelMessage("redisbungee-serverchange", data.toString());
|
||||
plugin.fireEvent(plugin.createPlayerChangedServerNetworkEvent(uuid, from, to));
|
||||
handleServerChangeRedis(uuid, to);
|
||||
}
|
||||
|
||||
private final JSONComponentSerializer COMPONENT_SERIALIZER =JSONComponentSerializer.json();
|
||||
|
||||
public void kickPlayer(UUID uuid, Component message) {
|
||||
if (!plugin.handlePlatformKick(uuid, message)) { // handle locally before SENDING a message
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("proxy", this.proxyId);
|
||||
data.put("uuid", uuid);
|
||||
data.put("message", COMPONENT_SERIALIZER.serialize(message));
|
||||
plugin.proxyDataManager().sendChannelMessage("redisbungee-kick", data.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleServerChangeRedis(UUID uuid, String server) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("server", server);
|
||||
data.put("last-server", server);
|
||||
unifiedJedis.hset("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", data);
|
||||
}
|
||||
|
||||
protected void addPlayer(final UUID uuid, final String name, final InetAddress inetAddress) {
|
||||
Map<String, String> redisData = new HashMap<>();
|
||||
redisData.put("last-online", String.valueOf(0));
|
||||
redisData.put("proxy", this.proxyId);
|
||||
redisData.put("ip", inetAddress.getHostAddress());
|
||||
unifiedJedis.hset("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", redisData);
|
||||
plugin.getUuidTranslator().persistInfo(name, uuid, this.unifiedJedis);
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("proxy", this.proxyId);
|
||||
data.put("uuid", uuid);
|
||||
plugin.proxyDataManager().sendChannelMessage("redisbungee-player-join", data.toString());
|
||||
plugin.fireEvent(plugin.createPlayerJoinedNetworkEvent(uuid));
|
||||
this.plugin.proxyDataManager().addPlayer(uuid);
|
||||
}
|
||||
|
||||
protected void removePlayer(UUID uuid) {
|
||||
unifiedJedis.hset("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", "last-online", String.valueOf(System.currentTimeMillis()));
|
||||
unifiedJedis.hdel("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", "server", "proxy", "ip");
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("proxy", this.proxyId);
|
||||
data.put("uuid", uuid);
|
||||
plugin.proxyDataManager().sendChannelMessage("redisbungee-player-leave", data.toString());
|
||||
plugin.fireEvent(plugin.createPlayerLeftNetworkEvent(uuid));
|
||||
this.plugin.proxyDataManager().removePlayer(uuid);
|
||||
}
|
||||
|
||||
|
||||
protected String getProxyFromRedis(UUID uuid) {
|
||||
return unifiedJedis.hget("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", "proxy");
|
||||
}
|
||||
|
||||
protected String getServerFromRedis(UUID uuid) {
|
||||
return unifiedJedis.hget("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", "server");
|
||||
}
|
||||
|
||||
protected String getLastServerFromRedis(UUID uuid) {
|
||||
return unifiedJedis.hget("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", "last-server");
|
||||
}
|
||||
|
||||
protected InetAddress getIpAddressFromRedis(UUID uuid) {
|
||||
String ip = unifiedJedis.hget("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", "ip");
|
||||
if (ip == null) return null;
|
||||
return InetAddresses.forString(ip);
|
||||
}
|
||||
|
||||
protected long getLastOnlineFromRedis(UUID uuid) {
|
||||
String unixString = unifiedJedis.hget("redis-bungee::" + this.networkId + "::player::" + uuid + "::data", "last-online");
|
||||
if (unixString == null) return -1;
|
||||
return Long.parseLong(unixString);
|
||||
}
|
||||
|
||||
public String getLastServerFor(UUID uuid) {
|
||||
return this.lastServerCache.get(uuid);
|
||||
}
|
||||
public String getServerFor(UUID uuid) {
|
||||
return this.serverCache.get(uuid);
|
||||
}
|
||||
|
||||
public String getProxyFor(UUID uuid) {
|
||||
return this.proxyCache.get(uuid);
|
||||
}
|
||||
|
||||
public InetAddress getIpFor(UUID uuid) {
|
||||
return this.ipCache.get(uuid);
|
||||
}
|
||||
|
||||
public long getLastOnline(UUID uuid) {
|
||||
return this.lastOnlineCache.get(uuid);
|
||||
}
|
||||
|
||||
public Multimap<String, UUID> serversToPlayers() {
|
||||
return this.serverToPlayersCache.get(SERVERS_TO_PLAYERS_KEY);
|
||||
}
|
||||
|
||||
protected Multimap<String, UUID> serversToPlayersBuilder(Object o) {
|
||||
try {
|
||||
return new RedisPipelineTask<Multimap<String, UUID>>(plugin) {
|
||||
private final Set<UUID> uuids = plugin.proxyDataManager().networkPlayers();
|
||||
private final ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
||||
|
||||
@Override
|
||||
public Multimap<String, UUID> doPooledPipeline(Pipeline pipeline) {
|
||||
HashMap<UUID, Response<String>> responses = new HashMap<>();
|
||||
for (UUID uuid : uuids) {
|
||||
responses.put(uuid, pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server"));
|
||||
}
|
||||
pipeline.sync();
|
||||
responses.forEach((uuid, response) -> builder.put(response.get(), uuid));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Multimap<String, UUID> clusterPipeline(ClusterPipeline pipeline) {
|
||||
HashMap<UUID, Response<String>> responses = new HashMap<>();
|
||||
for (UUID uuid : uuids) {
|
||||
responses.put(uuid, pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server"));
|
||||
}
|
||||
pipeline.sync();
|
||||
responses.forEach((uuid, response) -> builder.put(response.get(), uuid));
|
||||
return builder.build();
|
||||
}
|
||||
}.call();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
/*
|
||||
* 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.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.AbstractPayload;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.gson.AbstractPayloadSerializer;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.DeathPayload;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.HeartbeatPayload;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.PubSubPayload;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.RunCommandPayload;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.gson.DeathPayloadSerializer;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.gson.HeartbeatPayloadSerializer;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.gson.PubSubPayloadSerializer;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.gson.RunCommandPayloadSerializer;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisPipelineTask;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil;
|
||||
import redis.clients.jedis.*;
|
||||
import redis.clients.jedis.params.XAddParams;
|
||||
import redis.clients.jedis.params.XReadParams;
|
||||
import redis.clients.jedis.resps.StreamEntry;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
public abstract class ProxyDataManager implements Runnable {
|
||||
|
||||
private static final int MAX_ENTRIES = 10000;
|
||||
|
||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||
|
||||
private final UnifiedJedis unifiedJedis;
|
||||
|
||||
// data:
|
||||
// Proxy id, heartbeat (unix epoch from instant), players as int
|
||||
private final ConcurrentHashMap<String, HeartbeatPayload.HeartbeatData> heartbeats = new ConcurrentHashMap<>();
|
||||
|
||||
private final String networkId;
|
||||
|
||||
private final String proxyId;
|
||||
|
||||
private final String STREAM_ID;
|
||||
|
||||
// This different from proxy id, just to detect if there is duplicate proxy using same proxy id
|
||||
private final UUID dataManagerUUID = UUID.randomUUID();
|
||||
|
||||
protected final RedisBungeePlugin<?> plugin;
|
||||
|
||||
private final Gson gson = new GsonBuilder().registerTypeAdapter(AbstractPayload.class, new AbstractPayloadSerializer()).registerTypeAdapter(HeartbeatPayload.class, new HeartbeatPayloadSerializer()).registerTypeAdapter(DeathPayload.class, new DeathPayloadSerializer()).registerTypeAdapter(PubSubPayload.class, new PubSubPayloadSerializer()).registerTypeAdapter(RunCommandPayload.class, new RunCommandPayloadSerializer()).create();
|
||||
|
||||
public ProxyDataManager(RedisBungeePlugin<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
this.proxyId = this.plugin.configuration().getProxyId();
|
||||
this.unifiedJedis = plugin.getSummoner().obtainResource();
|
||||
this.destroyProxyMembers();
|
||||
this.networkId = plugin.configuration().networkId();
|
||||
this.STREAM_ID = "network-" + this.networkId + "-redisbungee-stream";
|
||||
}
|
||||
|
||||
public abstract Set<UUID> getLocalOnlineUUIDs();
|
||||
|
||||
public Set<UUID> getPlayersOn(String proxyId) {
|
||||
checkArgument(proxiesIds().contains(proxyId), proxyId + " is not a valid proxy ID");
|
||||
if (proxyId.equals(this.proxyId)) return this.getLocalOnlineUUIDs();
|
||||
if (!this.heartbeats.containsKey(proxyId)) {
|
||||
return new HashSet<>(); // return empty hashset or null?
|
||||
}
|
||||
return getProxyMembers(proxyId);
|
||||
}
|
||||
|
||||
public List<String> proxiesIds() {
|
||||
return Collections.list(this.heartbeats.keys());
|
||||
}
|
||||
|
||||
public synchronized void sendCommandTo(String proxyToRun, String command) {
|
||||
if (isClosed()) return;
|
||||
publishPayload(new RunCommandPayload(this.proxyId, proxyToRun, command));
|
||||
}
|
||||
|
||||
public synchronized void sendChannelMessage(String channel, String message) {
|
||||
if (isClosed()) return;
|
||||
this.plugin.fireEvent(this.plugin.createPubSubEvent(channel, message));
|
||||
publishPayload(new PubSubPayload(this.proxyId, channel, message));
|
||||
}
|
||||
|
||||
// call every 1 second
|
||||
public synchronized void publishHeartbeat() {
|
||||
if (isClosed()) return;
|
||||
HeartbeatPayload.HeartbeatData heartbeatData = new HeartbeatPayload.HeartbeatData(Instant.now().getEpochSecond(), this.getLocalOnlineUUIDs().size());
|
||||
this.heartbeats.put(this.proxyId(), heartbeatData);
|
||||
publishPayload(new HeartbeatPayload(this.proxyId, heartbeatData));
|
||||
}
|
||||
|
||||
public Set<UUID> networkPlayers() {
|
||||
try {
|
||||
return new RedisPipelineTask<Set<UUID>>(this.plugin) {
|
||||
@Override
|
||||
public Set<UUID> doPooledPipeline(Pipeline pipeline) {
|
||||
HashSet<Response<Set<String>>> responses = new HashSet<>();
|
||||
for (String proxyId : proxiesIds()) {
|
||||
responses.add(pipeline.smembers("redisbungee::" + networkId + "::proxies::" + proxyId + "::online-players"));
|
||||
}
|
||||
pipeline.sync();
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
for (Response<Set<String>> response : responses) {
|
||||
for (String stringUUID : response.get()) {
|
||||
uuids.add(UUID.fromString(stringUUID));
|
||||
}
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> clusterPipeline(ClusterPipeline pipeline) {
|
||||
HashSet<Response<Set<String>>> responses = new HashSet<>();
|
||||
for (String proxyId : proxiesIds()) {
|
||||
responses.add(pipeline.smembers("redisbungee::" + networkId + "::proxies::" + proxyId + "::online-players"));
|
||||
}
|
||||
pipeline.sync();
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
for (Response<Set<String>> response : responses) {
|
||||
for (String stringUUID : response.get()) {
|
||||
uuids.add(UUID.fromString(stringUUID));
|
||||
}
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
}.call();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("unable to get network players", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int totalNetworkPlayers() {
|
||||
int players = 0;
|
||||
for (HeartbeatPayload.HeartbeatData value : this.heartbeats.values()) {
|
||||
players += value.players();
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
public Map<String, Integer> eachProxyCount() {
|
||||
ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder();
|
||||
heartbeats.forEach((proxy, data) -> builder.put(proxy, data.players()));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
// Call on close
|
||||
private synchronized void publishDeath() {
|
||||
publishPayload(new DeathPayload(this.proxyId));
|
||||
}
|
||||
|
||||
private void publishPayload(AbstractPayload payload) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("payload", gson.toJson(payload));
|
||||
data.put("data-manager-uuid", this.dataManagerUUID.toString());
|
||||
data.put("class", payload.getClassName());
|
||||
this.unifiedJedis.xadd(STREAM_ID, XAddParams.xAddParams().maxLen(MAX_ENTRIES).id(StreamEntryID.NEW_ENTRY), data);
|
||||
}
|
||||
|
||||
|
||||
private void handleHeartBeat(HeartbeatPayload payload) {
|
||||
String id = payload.senderProxy();
|
||||
if (!heartbeats.containsKey(id)) {
|
||||
plugin.logInfo("Proxy {} has connected", id);
|
||||
}
|
||||
heartbeats.put(id, payload.data());
|
||||
}
|
||||
|
||||
|
||||
// call every 1 minutes
|
||||
public void correctionTask() {
|
||||
// let's check this proxy players
|
||||
Set<UUID> localOnlineUUIDs = getLocalOnlineUUIDs();
|
||||
Set<UUID> storedRedisUuids = getProxyMembers(this.proxyId);
|
||||
|
||||
if (!localOnlineUUIDs.equals(storedRedisUuids)) {
|
||||
plugin.logWarn("De-synced playerS set detected correcting....");
|
||||
Set<UUID> add = new HashSet<>(localOnlineUUIDs);
|
||||
Set<UUID> remove = new HashSet<>(storedRedisUuids);
|
||||
add.removeAll(storedRedisUuids);
|
||||
remove.removeAll(localOnlineUUIDs);
|
||||
for (UUID uuid : add) {
|
||||
plugin.logWarn("found {} that isn't in the set, adding it to the Corrected set", uuid);
|
||||
}
|
||||
for (UUID uuid : remove) {
|
||||
plugin.logWarn("found {} that does not belong to this proxy removing it from the corrected set", uuid);
|
||||
}
|
||||
try {
|
||||
new RedisPipelineTask<Void>(plugin) {
|
||||
@Override
|
||||
public Void doPooledPipeline(Pipeline pipeline) {
|
||||
Set<String> removeString = new HashSet<>();
|
||||
for (UUID uuid : remove) {
|
||||
removeString.add(uuid.toString());
|
||||
}
|
||||
Set<String> addString = new HashSet<>();
|
||||
for (UUID uuid : add) {
|
||||
addString.add(uuid.toString());
|
||||
}
|
||||
pipeline.srem("redisbungee::" + networkId + "::proxies::" + proxyId + "::online-players", removeString.toArray(new String[]{}));
|
||||
pipeline.sadd("redisbungee::" + networkId + "::proxies::" + proxyId + "::online-players", addString.toArray(new String[]{}));
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void clusterPipeline(ClusterPipeline pipeline) {
|
||||
Set<String> removeString = new HashSet<>();
|
||||
for (UUID uuid : remove) {
|
||||
removeString.add(uuid.toString());
|
||||
}
|
||||
Set<String> addString = new HashSet<>();
|
||||
for (UUID uuid : add) {
|
||||
addString.add(uuid.toString());
|
||||
}
|
||||
pipeline.srem("redisbungee::" + networkId + "::proxies::" + proxyId + "::online-players", removeString.toArray(new String[]{}));
|
||||
pipeline.sadd("redisbungee::" + networkId + "::proxies::" + proxyId + "::online-players", addString.toArray(new String[]{}));
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
}.call();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
plugin.logInfo("Player set has been corrected!");
|
||||
}
|
||||
|
||||
|
||||
// handle dead proxies "THAT" Didn't send death payload but considered dead due TIMEOUT ~30 seconds
|
||||
final Set<String> deadProxies = new HashSet<>();
|
||||
for (Map.Entry<String, HeartbeatPayload.HeartbeatData> stringHeartbeatDataEntry : this.heartbeats.entrySet()) {
|
||||
String id = stringHeartbeatDataEntry.getKey();
|
||||
long heartbeat = stringHeartbeatDataEntry.getValue().heartbeat();
|
||||
if (Instant.now().getEpochSecond() - heartbeat > RedisUtil.PROXY_TIMEOUT) {
|
||||
deadProxies.add(id);
|
||||
cleanProxy(id);
|
||||
}
|
||||
}
|
||||
try {
|
||||
new RedisPipelineTask<Void>(plugin) {
|
||||
@Override
|
||||
public Void doPooledPipeline(Pipeline pipeline) {
|
||||
for (String deadProxy : deadProxies) {
|
||||
pipeline.del("redisbungee::" + networkId + "::proxies::" + deadProxy + "::online-players");
|
||||
}
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void clusterPipeline(ClusterPipeline pipeline) {
|
||||
for (String deadProxy : deadProxies) {
|
||||
pipeline.del("redisbungee::" + networkId + "::proxies::" + deadProxy + "::online-players");
|
||||
}
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
}.call();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleProxyDeath(DeathPayload payload) {
|
||||
cleanProxy(payload.senderProxy());
|
||||
}
|
||||
|
||||
private void cleanProxy(String id) {
|
||||
if (id.equals(this.proxyId())) {
|
||||
return;
|
||||
}
|
||||
for (UUID uuid : getProxyMembers(id)) plugin.fireEvent(plugin.createPlayerLeftNetworkEvent(uuid));
|
||||
this.heartbeats.remove(id);
|
||||
plugin.logInfo("Proxy {} has disconnected", id);
|
||||
}
|
||||
|
||||
private void handleChannelMessage(PubSubPayload payload) {
|
||||
String channel = payload.channel();
|
||||
String message = payload.message();
|
||||
this.plugin.fireEvent(this.plugin.createPubSubEvent(channel, message));
|
||||
}
|
||||
|
||||
protected abstract void handlePlatformCommandExecution(String command);
|
||||
|
||||
private void handleCommand(RunCommandPayload payload) {
|
||||
String proxyToRun = payload.proxyToRun();
|
||||
String command = payload.command();
|
||||
if (proxyToRun.equals("allservers") || proxyToRun.equals(this.proxyId())) {
|
||||
handlePlatformCommandExecution(command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addPlayer(UUID uuid) {
|
||||
this.unifiedJedis.sadd("redisbungee::" + this.networkId + "::proxies::" + this.proxyId + "::online-players", uuid.toString());
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
this.unifiedJedis.srem("redisbungee::" + this.networkId + "::proxies::" + this.proxyId + "::online-players", uuid.toString());
|
||||
}
|
||||
|
||||
private void destroyProxyMembers() {
|
||||
unifiedJedis.del("redisbungee::" + this.networkId + "::proxies::" + this.proxyId + "::online-players");
|
||||
}
|
||||
|
||||
private Set<UUID> getProxyMembers(String proxyId) {
|
||||
Set<String> uuidsStrings = unifiedJedis.smembers("redisbungee::" + this.networkId + "::proxies::" + proxyId + "::online-players");
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
for (String proxyMember : uuidsStrings) {
|
||||
uuids.add(UUID.fromString(proxyMember));
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
|
||||
private StreamEntryID lastStreamEntryID;
|
||||
|
||||
// polling from stream
|
||||
@Override
|
||||
public void run() {
|
||||
while (!isClosed()) {
|
||||
try {
|
||||
List<java.util.Map.Entry<String, List<StreamEntry>>> data = unifiedJedis.xread(XReadParams.xReadParams().block(0), Collections.singletonMap(STREAM_ID, lastStreamEntryID != null ? lastStreamEntryID : StreamEntryID.LAST_ENTRY));
|
||||
for (Map.Entry<String, List<StreamEntry>> datum : data) {
|
||||
for (StreamEntry streamEntry : datum.getValue()) {
|
||||
this.lastStreamEntryID = streamEntry.getID();
|
||||
String payloadData = streamEntry.getFields().get("payload");
|
||||
String clazz = streamEntry.getFields().get("class");
|
||||
UUID payloadDataManagerUUID = UUID.fromString(streamEntry.getFields().get("data-manager-uuid"));
|
||||
|
||||
AbstractPayload unknownPayload = (AbstractPayload) gson.fromJson(payloadData, Class.forName(clazz));
|
||||
|
||||
if (unknownPayload.senderProxy().equals(this.proxyId)) {
|
||||
if (!payloadDataManagerUUID.equals(this.dataManagerUUID)) {
|
||||
plugin.logWarn("detected other proxy is using same ID! {} this can cause issues, please shutdown this proxy and change the id!", this.proxyId);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (unknownPayload instanceof HeartbeatPayload payload) {
|
||||
handleHeartBeat(payload);
|
||||
} else if (unknownPayload instanceof DeathPayload payload) {
|
||||
handleProxyDeath(payload);
|
||||
} else if (unknownPayload instanceof RunCommandPayload payload) {
|
||||
handleCommand(payload);
|
||||
} else if (unknownPayload instanceof PubSubPayload payload) {
|
||||
handleChannelMessage(payload);
|
||||
} else {
|
||||
plugin.logWarn("got unknown data manager payload: {}", unknownPayload.getClassName());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.plugin.logFatal("an error has occurred in the stream", e);
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
closed.set(true);
|
||||
this.publishDeath();
|
||||
this.heartbeats.clear();
|
||||
this.destroyProxyMembers();
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return closed.get();
|
||||
}
|
||||
|
||||
public String proxyId() {
|
||||
return proxyId;
|
||||
}
|
||||
|
||||
public UnifiedJedis unifiedJedis() {
|
||||
return unifiedJedis;
|
||||
}
|
||||
|
||||
public String networkId() {
|
||||
return networkId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.AbstractRedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.LangConfiguration;
|
||||
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.util.uuid.UUIDTranslator;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* <p>
|
||||
* Reason this is interface because some proxies implementations require the user to extend class for plugins for example bungeecord.
|
||||
*
|
||||
* @author Ham1255
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public interface RedisBungeePlugin<P> extends EventsPlatform {
|
||||
|
||||
default void initialize() {
|
||||
|
||||
}
|
||||
|
||||
default void stop() {
|
||||
|
||||
}
|
||||
|
||||
void logInfo(String msg);
|
||||
|
||||
void logInfo(String format, Object... object);
|
||||
|
||||
void logWarn(String msg);
|
||||
|
||||
void logWarn(String format, Object... object);
|
||||
|
||||
void logFatal(String msg);
|
||||
|
||||
void logFatal(String format, Throwable throwable);
|
||||
|
||||
RedisBungeeConfiguration configuration();
|
||||
|
||||
LangConfiguration langConfiguration();
|
||||
|
||||
Summoner<?> getSummoner();
|
||||
|
||||
RedisBungeeMode getRedisBungeeMode();
|
||||
|
||||
AbstractRedisBungeeAPI getAbstractRedisBungeeApi();
|
||||
|
||||
ProxyDataManager proxyDataManager();
|
||||
|
||||
PlayerDataManager<P, ?, ?, ?, ?, ?, ?> playerDataManager();
|
||||
|
||||
UUIDTranslator getUuidTranslator();
|
||||
|
||||
boolean isOnlineMode();
|
||||
|
||||
P getPlayer(UUID uuid);
|
||||
|
||||
P getPlayer(String name);
|
||||
|
||||
UUID getPlayerUUID(String player);
|
||||
|
||||
|
||||
String getPlayerName(UUID player);
|
||||
|
||||
boolean handlePlatformKick(UUID uuid, Component message);
|
||||
|
||||
String getPlayerServerName(P player);
|
||||
|
||||
boolean isPlayerOnAServer(P player);
|
||||
|
||||
InetAddress getPlayerIp(P player);
|
||||
|
||||
void executeAsync(Runnable runnable);
|
||||
|
||||
void executeAsyncAfter(Runnable runnable, TimeUnit timeUnit, int time);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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 net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This language support implementation is temporarily
|
||||
* until I come up with better system but for now we will use Maps instead :/
|
||||
* Todo: possible usage of adventure api
|
||||
*/
|
||||
public class LangConfiguration {
|
||||
|
||||
private interface RegistrableMessages {
|
||||
|
||||
void register(String id, Locale locale, String miniMessage);
|
||||
|
||||
void test(Locale locale);
|
||||
|
||||
default void throwError(Locale locale, String where) {
|
||||
throw new IllegalStateException("Language system in `" + where + "` found missing entries for " + locale.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Messages implements RegistrableMessages{
|
||||
|
||||
private final Map<Locale, Component> LOGGED_IN_FROM_OTHER_LOCATION;
|
||||
private final Map<Locale, Component> ALREADY_LOGGED_IN;
|
||||
private final Map<Locale, String> SERVER_CONNECTING;
|
||||
private final Map<Locale, String> SERVER_NOT_FOUND;
|
||||
|
||||
private final Locale defaultLocale;
|
||||
|
||||
public Messages(Locale defaultLocale) {
|
||||
LOGGED_IN_FROM_OTHER_LOCATION = new HashMap<>();
|
||||
ALREADY_LOGGED_IN = new HashMap<>();
|
||||
SERVER_CONNECTING = new HashMap<>();
|
||||
SERVER_NOT_FOUND = new HashMap<>();
|
||||
this.defaultLocale = defaultLocale;
|
||||
}
|
||||
|
||||
public void register(String id, Locale locale, String miniMessage) {
|
||||
switch (id) {
|
||||
case "server-not-found" -> SERVER_NOT_FOUND.put(locale, miniMessage);
|
||||
case "server-connecting" -> SERVER_CONNECTING.put(locale, miniMessage);
|
||||
case "logged-in-other-location" -> LOGGED_IN_FROM_OTHER_LOCATION.put(locale, MiniMessage.miniMessage().deserialize(miniMessage));
|
||||
case "already-logged-in" -> ALREADY_LOGGED_IN.put(locale, MiniMessage.miniMessage().deserialize(miniMessage));
|
||||
}
|
||||
}
|
||||
|
||||
public Component alreadyLoggedIn(Locale locale) {
|
||||
if (ALREADY_LOGGED_IN.containsKey(locale)) return ALREADY_LOGGED_IN.get(locale);
|
||||
return ALREADY_LOGGED_IN.get(defaultLocale);
|
||||
}
|
||||
|
||||
// there is no way to know whats client locale during login so just default to use default locale MESSAGES.
|
||||
public Component alreadyLoggedIn() {
|
||||
return this.alreadyLoggedIn(this.defaultLocale);
|
||||
}
|
||||
|
||||
public Component loggedInFromOtherLocation(Locale locale) {
|
||||
if (LOGGED_IN_FROM_OTHER_LOCATION.containsKey(locale)) return LOGGED_IN_FROM_OTHER_LOCATION.get(locale);
|
||||
return LOGGED_IN_FROM_OTHER_LOCATION.get(defaultLocale);
|
||||
}
|
||||
|
||||
// there is no way to know what's client locale during login so just default to use default locale MESSAGES.
|
||||
public Component loggedInFromOtherLocation() {
|
||||
return this.loggedInFromOtherLocation(this.defaultLocale);
|
||||
}
|
||||
|
||||
public Component serverConnecting(Locale locale, String server) {
|
||||
String miniMessage;
|
||||
if (SERVER_CONNECTING.containsKey(locale)) {
|
||||
miniMessage = SERVER_CONNECTING.get(locale);
|
||||
} else {
|
||||
miniMessage = SERVER_CONNECTING.get(defaultLocale);
|
||||
}
|
||||
return MiniMessage.miniMessage().deserialize(miniMessage, Placeholder.parsed("server", server));
|
||||
}
|
||||
|
||||
public Component serverConnecting(String server) {
|
||||
return this.serverConnecting(this.defaultLocale, server);
|
||||
}
|
||||
|
||||
public Component serverNotFound(Locale locale, String server) {
|
||||
String miniMessage;
|
||||
if (SERVER_NOT_FOUND.containsKey(locale)) {
|
||||
miniMessage = SERVER_NOT_FOUND.get(locale);
|
||||
} else {
|
||||
miniMessage = SERVER_NOT_FOUND.get(defaultLocale);
|
||||
}
|
||||
return MiniMessage.miniMessage().deserialize(miniMessage, Placeholder.parsed("server", server));
|
||||
}
|
||||
|
||||
public Component serverNotFound(String server) {
|
||||
return this.serverNotFound(this.defaultLocale, server);
|
||||
}
|
||||
|
||||
|
||||
// tests locale if set CORRECTLY or just throw if not
|
||||
public void test(Locale locale) {
|
||||
if (!(LOGGED_IN_FROM_OTHER_LOCATION.containsKey(locale) && ALREADY_LOGGED_IN.containsKey(locale) && SERVER_CONNECTING.containsKey(locale) && SERVER_NOT_FOUND.containsKey(locale))) {
|
||||
throwError(locale, "messages");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Component redisBungeePrefix;
|
||||
|
||||
private final Locale defaultLanguage;
|
||||
|
||||
private final boolean useClientLanguage;
|
||||
|
||||
private final Messages messages;
|
||||
|
||||
public LangConfiguration(Component redisBungeePrefix, Locale defaultLanguage, boolean useClientLanguage, Messages messages) {
|
||||
this.redisBungeePrefix = redisBungeePrefix;
|
||||
this.defaultLanguage = defaultLanguage;
|
||||
this.useClientLanguage = useClientLanguage;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public Component redisBungeePrefix() {
|
||||
return redisBungeePrefix;
|
||||
}
|
||||
|
||||
public Locale defaultLanguage() {
|
||||
return defaultLanguage;
|
||||
}
|
||||
|
||||
public boolean useClientLanguage() {
|
||||
return useClientLanguage;
|
||||
}
|
||||
|
||||
public Messages messages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.net.InetAddresses;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
|
||||
public class RedisBungeeConfiguration {
|
||||
|
||||
private final String proxyId;
|
||||
private final List<InetAddress> exemptAddresses;
|
||||
private final boolean kickWhenOnline;
|
||||
|
||||
private final boolean handleReconnectToLastServer;
|
||||
private final boolean handleMotd;
|
||||
|
||||
private final CommandsConfiguration commandsConfiguration;
|
||||
private final String networkId;
|
||||
|
||||
|
||||
public RedisBungeeConfiguration(String networkId, String proxyId, List<String> exemptAddresses, boolean kickWhenOnline, boolean handleReconnectToLastServer, boolean handleMotd, CommandsConfiguration commandsConfiguration) {
|
||||
this.proxyId = proxyId;
|
||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
||||
for (String s : exemptAddresses) {
|
||||
addressBuilder.add(InetAddresses.forString(s));
|
||||
}
|
||||
this.exemptAddresses = addressBuilder.build();
|
||||
this.kickWhenOnline = kickWhenOnline;
|
||||
this.handleReconnectToLastServer = handleReconnectToLastServer;
|
||||
this.handleMotd = handleMotd;
|
||||
this.commandsConfiguration = commandsConfiguration;
|
||||
this.networkId = networkId;
|
||||
}
|
||||
|
||||
public String getProxyId() {
|
||||
return proxyId;
|
||||
}
|
||||
|
||||
public List<InetAddress> getExemptAddresses() {
|
||||
return exemptAddresses;
|
||||
}
|
||||
|
||||
public boolean kickWhenOnline() {
|
||||
return kickWhenOnline;
|
||||
}
|
||||
|
||||
public boolean handleMotd() {
|
||||
return this.handleMotd;
|
||||
}
|
||||
|
||||
public boolean handleReconnectToLastServer() {
|
||||
return this.handleReconnectToLastServer;
|
||||
}
|
||||
|
||||
public record CommandsConfiguration(boolean redisbungeeEnabled, boolean redisbungeeLegacyEnabled,
|
||||
@Nullable LegacySubCommandsConfiguration legacySubCommandsConfiguration) {
|
||||
|
||||
}
|
||||
|
||||
public record LegacySubCommandsConfiguration(boolean findEnabled, boolean glistEnabled, boolean ipEnabled,
|
||||
boolean lastseenEnabled, boolean plistEnabled, boolean pproxyEnabled,
|
||||
boolean sendtoallEnabled, boolean serveridEnabled,
|
||||
boolean serveridsEnabled, boolean installFind, boolean installGlist, boolean installIp,
|
||||
boolean installLastseen, boolean installPlist, boolean installPproxy,
|
||||
boolean installSendtoall, boolean installServerid,
|
||||
boolean installServerids) {
|
||||
}
|
||||
|
||||
public CommandsConfiguration commandsConfiguration() {
|
||||
return commandsConfiguration;
|
||||
}
|
||||
|
||||
public String networkId() {
|
||||
return networkId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* 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.loaders;
|
||||
|
||||
|
||||
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.config.RedisBungeeConfiguration;
|
||||
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.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
public interface ConfigLoader extends GenericConfigLoader {
|
||||
|
||||
int CONFIG_VERSION = 2;
|
||||
|
||||
default void loadConfig(RedisBungeePlugin<?> plugin, Path dataFolder) throws IOException {
|
||||
Path configFile = createConfigFile(dataFolder, "config.yml", "config.yml");
|
||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
||||
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
||||
if (node.getNode("config-version").getInt(0) != CONFIG_VERSION) {
|
||||
handleOldConfig(dataFolder, "config.yml", "config.yml");
|
||||
node = yamlConfigurationFileLoader.load();
|
||||
}
|
||||
final boolean useSSL = node.getNode("useSSL").getBoolean(false);
|
||||
final boolean kickWhenOnline = node.getNode("kick-when-online").getBoolean(true);
|
||||
String redisPassword = node.getNode("redis-password").getString("");
|
||||
String redisUsername = node.getNode("redis-username").getString("");
|
||||
String networkId = node.getNode("network-id").getString("main");
|
||||
String proxyId = node.getNode("proxy-id").getString("proxy-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 ((redisUsername.isEmpty() || redisUsername.equals("none"))) {
|
||||
redisUsername = null;
|
||||
}
|
||||
// env var
|
||||
String proxyIdFromEnv = System.getenv("REDISBUNGEE_PROXY_ID");
|
||||
if (proxyIdFromEnv != null) {
|
||||
plugin.logInfo("Overriding current configured proxy id {} and been set to {} by Environment variable REDISBUNGEE_PROXY_ID", proxyId, proxyIdFromEnv);
|
||||
proxyId = proxyIdFromEnv;
|
||||
}
|
||||
|
||||
String networkIdFromEnv = System.getenv("REDISBUNGEE_NETWORK_ID");
|
||||
if (networkIdFromEnv != null) {
|
||||
plugin.logInfo("Overriding current configured network id {} and been set to {} by Environment variable REDISBUNGEE_NETWORK_ID", networkId, networkIdFromEnv);
|
||||
networkId = networkIdFromEnv;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
if (networkId.isEmpty()) {
|
||||
networkId = "main";
|
||||
plugin.logWarn("network id was empty and replaced with 'main'");
|
||||
}
|
||||
|
||||
plugin.logInfo("Loaded network id " + networkId);
|
||||
|
||||
|
||||
|
||||
boolean reconnectToLastServer = node.getNode("reconnect-to-last-server").getBoolean();
|
||||
boolean handleMotd = node.getNode("handle-motd").getBoolean(true);
|
||||
plugin.logInfo("handle reconnect to last server: {}", reconnectToLastServer);
|
||||
plugin.logInfo("handle motd: {}", handleMotd);
|
||||
|
||||
|
||||
// commands
|
||||
boolean redisBungeeEnabled = node.getNode("commands", "redisbungee", "enabled").getBoolean(true);
|
||||
boolean redisBungeeLegacyEnabled =node.getNode("commands", "redisbungee-legacy", "enabled").getBoolean(false);
|
||||
|
||||
boolean glistEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "glist", "enabled").getBoolean(false);
|
||||
boolean findEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "find", "enabled").getBoolean(false);
|
||||
boolean lastseenEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "lastseen", "enabled").getBoolean(false);
|
||||
boolean ipEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "ip", "enabled").getBoolean(false);
|
||||
boolean pproxyEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "pproxy", "enabled").getBoolean(false);
|
||||
boolean sendToAllEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "sendtoall", "enabled").getBoolean(false);
|
||||
boolean serverIdEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "serverid", "enabled").getBoolean(false);
|
||||
boolean serverIdsEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "serverids", "enabled").getBoolean(false);
|
||||
boolean pListEnabled = node.getNode("commands", "redisbungee-legacy", "subcommands", "plist", "enabled").getBoolean(false);
|
||||
|
||||
boolean installGlist = node.getNode("commands", "redisbungee-legacy", "subcommands", "glist", "install").getBoolean(false);
|
||||
boolean installFind = node.getNode("commands", "redisbungee-legacy", "subcommands", "find", "install").getBoolean(false);
|
||||
boolean installLastseen = node.getNode("commands", "redisbungee-legacy", "subcommands", "lastseen", "install").getBoolean(false);
|
||||
boolean installIp = node.getNode("commands", "redisbungee-legacy", "subcommands", "ip", "install").getBoolean(false);
|
||||
boolean installPproxy = node.getNode("commands", "redisbungee-legacy", "subcommands", "pproxy", "install").getBoolean(false);
|
||||
boolean installSendToAll = node.getNode("commands", "redisbungee-legacy", "subcommands", "sendtoall", "install").getBoolean(false);
|
||||
boolean installServerid = node.getNode("commands", "redisbungee-legacy", "subcommands", "serverid", "install").getBoolean(false);
|
||||
boolean installServerIds = node.getNode("commands", "redisbungee-legacy", "subcommands", "serverids", "install").getBoolean(false);
|
||||
boolean installPlist = node.getNode("commands", "redisbungee-legacy", "subcommands", "plist", "install").getBoolean(false);
|
||||
|
||||
|
||||
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(networkId, proxyId, exemptAddresses, kickWhenOnline, reconnectToLastServer, handleMotd, new RedisBungeeConfiguration.CommandsConfiguration(
|
||||
redisBungeeEnabled, redisBungeeLegacyEnabled,
|
||||
new RedisBungeeConfiguration.LegacySubCommandsConfiguration(
|
||||
findEnabled, glistEnabled, ipEnabled,
|
||||
lastseenEnabled, pListEnabled, pproxyEnabled,
|
||||
sendToAllEnabled, serverIdEnabled, serverIdsEnabled,
|
||||
installFind, installGlist, installIp,
|
||||
installLastseen, installPlist, installPproxy,
|
||||
installSendToAll, installServerid, installServerIds)
|
||||
));
|
||||
Summoner<?> summoner;
|
||||
RedisBungeeMode redisBungeeMode;
|
||||
if (useSSL) {
|
||||
plugin.logInfo("Using ssl");
|
||||
}
|
||||
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().user(redisUsername).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(false)) {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setMaxTotal(node.getNode("compatibility-max-connections").getInt(3));
|
||||
config.setBlockWhenExhausted(true);
|
||||
jedisPool = new JedisPool(config, redisServer, redisPort, 5000, redisUsername, 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().user(redisUsername).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);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.loaders;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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.time.Instant;
|
||||
|
||||
|
||||
public interface GenericConfigLoader {
|
||||
|
||||
// CHANGES on every reboot
|
||||
String RANDOM_OLD = "backup-" + Instant.now().getEpochSecond();
|
||||
|
||||
default Path createConfigFile(Path dataFolder, String configFile, @Nullable String defaultResourceID) throws IOException {
|
||||
if (Files.notExists(dataFolder)) {
|
||||
Files.createDirectory(dataFolder);
|
||||
}
|
||||
Path file = dataFolder.resolve(configFile);
|
||||
if (Files.notExists(file) && defaultResourceID != null) {
|
||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream(defaultResourceID)) {
|
||||
Files.createFile(file);
|
||||
assert in != null;
|
||||
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
default void handleOldConfig(Path dataFolder, String configFile, @Nullable String defaultResourceID) throws IOException {
|
||||
Path oldConfigFolder = dataFolder.resolve("old_config");
|
||||
if (Files.notExists(oldConfigFolder)) {
|
||||
Files.createDirectory(oldConfigFolder);
|
||||
}
|
||||
Path randomStoreConfigDirectory = oldConfigFolder.resolve(RANDOM_OLD);
|
||||
if (Files.notExists(randomStoreConfigDirectory)) {
|
||||
Files.createDirectory(randomStoreConfigDirectory);
|
||||
}
|
||||
Path oldConfigPath = dataFolder.resolve(configFile);
|
||||
|
||||
Files.move(oldConfigPath, randomStoreConfigDirectory.resolve(configFile));
|
||||
createConfigFile(dataFolder, configFile, defaultResourceID);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.loaders;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.LangConfiguration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
public interface LangConfigLoader extends GenericConfigLoader {
|
||||
|
||||
int CONFIG_VERSION = 1;
|
||||
|
||||
default void loadLangConfig(RedisBungeePlugin<?> plugin, Path dataFolder) throws IOException {
|
||||
Path configFile = createConfigFile(dataFolder, "lang.yml", "lang.yml");
|
||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
||||
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
||||
if (node.getNode("config-version").getInt(0) != CONFIG_VERSION) {
|
||||
handleOldConfig(dataFolder, "lang.yml", "lang.yml");
|
||||
node = yamlConfigurationFileLoader.load();
|
||||
}
|
||||
// MINI message serializer
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
Component prefix = miniMessage.deserialize(node.getNode("prefix").getString("<color:red>[<color:yellow>Redis<color:red>Bungee]"));
|
||||
Locale defaultLocale = Locale.forLanguageTag(node.getNode("default-locale").getString("en-us"));
|
||||
boolean useClientLocale = node.getNode("use-client-locale").getBoolean(true);
|
||||
LangConfiguration.Messages messages = new LangConfiguration.Messages(defaultLocale);
|
||||
node.getNode("messages").getChildrenMap().forEach((key, childNode) -> childNode.getChildrenMap().forEach((childKey, childChildNode) -> {
|
||||
messages.register(key.toString(), Locale.forLanguageTag(childKey.toString()), childChildNode.getString());
|
||||
}));
|
||||
messages.test(defaultLocale);
|
||||
|
||||
onLangConfigLoad(new LangConfiguration(prefix, defaultLocale, useClientLocale, messages));
|
||||
}
|
||||
|
||||
|
||||
void onLangConfigLoad(LangConfiguration langConfiguration);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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 {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee.api.payloads;
|
||||
|
||||
public abstract class AbstractPayload {
|
||||
|
||||
private final String senderProxy;
|
||||
|
||||
public AbstractPayload(String proxyId) {
|
||||
this.senderProxy = proxyId;
|
||||
}
|
||||
|
||||
public AbstractPayload(String senderProxy, String className) {
|
||||
this.senderProxy = senderProxy;
|
||||
}
|
||||
|
||||
public String senderProxy() {
|
||||
return senderProxy;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.payloads.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.AbstractPayload;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class AbstractPayloadSerializer implements JsonSerializer<AbstractPayload>, JsonDeserializer<AbstractPayload> {
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractPayload deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
return new AbstractPayload(jsonObject.get("proxy").getAsString(), jsonObject.get("class").getAsString()) {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(AbstractPayload src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.add("proxy", new JsonPrimitive(src.senderProxy()));
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.payloads.proxy;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.AbstractPayload;
|
||||
|
||||
public class DeathPayload extends AbstractPayload {
|
||||
public DeathPayload(String proxyId) {
|
||||
super(proxyId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.payloads.proxy;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.AbstractPayload;
|
||||
|
||||
public class HeartbeatPayload extends AbstractPayload {
|
||||
|
||||
public record HeartbeatData(long heartbeat, int players) {
|
||||
|
||||
}
|
||||
|
||||
private final HeartbeatData data;
|
||||
|
||||
public HeartbeatPayload(String proxyId, HeartbeatData data) {
|
||||
super(proxyId);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public HeartbeatData data() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.payloads.proxy;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.AbstractPayload;
|
||||
|
||||
public class PubSubPayload extends AbstractPayload {
|
||||
|
||||
private final String channel;
|
||||
private final String message;
|
||||
|
||||
|
||||
public PubSubPayload(String proxyId, String channel, String message) {
|
||||
super(proxyId);
|
||||
this.channel = channel;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String channel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public String message() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.payloads.proxy;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.AbstractPayload;
|
||||
|
||||
public class RunCommandPayload extends AbstractPayload {
|
||||
|
||||
|
||||
private final String proxyToRun;
|
||||
|
||||
private final String command;
|
||||
|
||||
|
||||
public RunCommandPayload(String proxyId, String proxyToRun, String command) {
|
||||
super(proxyId);
|
||||
this.proxyToRun = proxyToRun;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String proxyToRun() {
|
||||
return proxyToRun;
|
||||
}
|
||||
|
||||
public String command() {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.payloads.proxy.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.DeathPayload;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class DeathPayloadSerializer implements JsonSerializer<DeathPayload>, JsonDeserializer<DeathPayload> {
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
|
||||
@Override
|
||||
public DeathPayload deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
String senderProxy = jsonObject.get("proxy").getAsString();
|
||||
return new DeathPayload(senderProxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(DeathPayload src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.add("proxy", new JsonPrimitive(src.senderProxy()));
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.payloads.proxy.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.HeartbeatPayload;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class HeartbeatPayloadSerializer implements JsonSerializer<HeartbeatPayload>, JsonDeserializer<HeartbeatPayload> {
|
||||
|
||||
|
||||
@Override
|
||||
public HeartbeatPayload deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
String senderProxy = jsonObject.get("proxy").getAsString();
|
||||
long heartbeat = jsonObject.get("heartbeat").getAsLong();
|
||||
int players = jsonObject.get("players").getAsInt();
|
||||
return new HeartbeatPayload(senderProxy, new HeartbeatPayload.HeartbeatData(heartbeat, players));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(HeartbeatPayload src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.add("proxy", new JsonPrimitive(src.senderProxy()));
|
||||
jsonObject.add("heartbeat", new JsonPrimitive(src.data().heartbeat()));
|
||||
jsonObject.add("players", new JsonPrimitive(src.data().players()));
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.payloads.proxy.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.PubSubPayload;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class PubSubPayloadSerializer implements JsonSerializer<PubSubPayload>, JsonDeserializer<PubSubPayload> {
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
|
||||
@Override
|
||||
public PubSubPayload deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
String senderProxy = jsonObject.get("proxy").getAsString();
|
||||
String channel = jsonObject.get("channel").getAsString();
|
||||
String message = jsonObject.get("message").getAsString();
|
||||
return new PubSubPayload(senderProxy, channel, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(PubSubPayload src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.add("proxy", new JsonPrimitive(src.senderProxy()));
|
||||
jsonObject.add("channel", new JsonPrimitive(src.channel()));
|
||||
jsonObject.add("message", context.serialize(src.message()));
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.payloads.proxy.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.payloads.proxy.RunCommandPayload;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class RunCommandPayloadSerializer implements JsonSerializer<RunCommandPayload>, JsonDeserializer<RunCommandPayload> {
|
||||
|
||||
|
||||
@Override
|
||||
public RunCommandPayload deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
String senderProxy = jsonObject.get("proxy").getAsString();
|
||||
String proxyToRun = jsonObject.get("proxy-to-run").getAsString();
|
||||
String command = jsonObject.get("command").getAsString();
|
||||
return new RunCommandPayload(senderProxy, proxyToRun, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(RunCommandPayload src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.add("proxy", new JsonPrimitive(src.senderProxy()));
|
||||
jsonObject.add("proxy-to-run", new JsonPrimitive(src.proxyToRun()));
|
||||
jsonObject.add("command", context.serialize(src.command()));
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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> {
|
||||
private 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(10));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.time.Duration;
|
||||
|
||||
|
||||
public class NotClosableJedisCluster extends JedisCluster {
|
||||
|
||||
NotClosableJedisCluster(ClusterConnectionProvider provider, int maxAttempts, Duration maxTotalRetriesDuration) {
|
||||
super(provider, maxAttempts, maxTotalRetriesDuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.UnifiedJedis;
|
||||
|
||||
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 UnifiedJedis> extends Closeable {
|
||||
|
||||
P obtainResource();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 redis.clients.jedis.*;
|
||||
|
||||
public abstract class RedisPipelineTask<T> extends RedisTask<T> {
|
||||
|
||||
|
||||
public RedisPipelineTask(AbstractRedisBungeeAPI api) {
|
||||
super(api);
|
||||
}
|
||||
|
||||
public RedisPipelineTask(RedisBungeePlugin<?> plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public T unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
if (unifiedJedis instanceof JedisPooled pooled) {
|
||||
try (Pipeline pipeline = pooled.pipelined()) {
|
||||
return doPooledPipeline(pipeline);
|
||||
}
|
||||
} else if (unifiedJedis instanceof JedisCluster jedisCluster) {
|
||||
try (ClusterPipeline pipeline = jedisCluster.pipelined()) {
|
||||
return clusterPipeline(pipeline);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract T doPooledPipeline(Pipeline pipeline);
|
||||
|
||||
public abstract T clusterPipeline(ClusterPipeline pipeline);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.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 redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Since Jedis now have UnifiedJedis which basically extended by cluster / single connections classes
|
||||
* can help us to have shared code.
|
||||
*/
|
||||
public abstract class RedisTask<V> implements Runnable, Callable<V> {
|
||||
|
||||
protected final Summoner<?> summoner;
|
||||
|
||||
protected final RedisBungeeMode mode;
|
||||
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
return this.execute();
|
||||
}
|
||||
|
||||
public RedisTask(AbstractRedisBungeeAPI api) {
|
||||
this.summoner = api.getSummoner();
|
||||
this.mode = api.getMode();
|
||||
}
|
||||
|
||||
public RedisTask(RedisBungeePlugin<?> plugin) {
|
||||
this.summoner = plugin.getSummoner();
|
||||
this.mode = plugin.getRedisBungeeMode();
|
||||
}
|
||||
|
||||
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 (mode == RedisBungeeMode.SINGLE) {
|
||||
JedisPooledSummoner jedisSummoner = (JedisPooledSummoner) summoner;
|
||||
return this.unifiedJedisTask(jedisSummoner.obtainResource());
|
||||
} else if (mode == RedisBungeeMode.CLUSTER) {
|
||||
JedisClusterSummoner jedisClusterSummoner = (JedisClusterSummoner) summoner;
|
||||
return this.unifiedJedisTask(jedisClusterSummoner.obtainResource());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.google.gson.Gson;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.CachedUUIDEntry;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class UUIDCleanupTask extends RedisTask<Void>{
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
private final RedisBungeePlugin<?> plugin;
|
||||
|
||||
public UUIDCleanupTask(RedisBungeePlugin<?> plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
// this code is inspired from https://github.com/minecrafter/redisbungeeclean
|
||||
@Override
|
||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
try {
|
||||
final long number = unifiedJedis.hlen("uuid-cache");
|
||||
plugin.logInfo("Found {} entries", number);
|
||||
ArrayList<String> fieldsToRemove = new ArrayList<>();
|
||||
unifiedJedis.hgetAll("uuid-cache").forEach((field, data) -> {
|
||||
CachedUUIDEntry cachedUUIDEntry = gson.fromJson(data, CachedUUIDEntry.class);
|
||||
if (cachedUUIDEntry.expired()) {
|
||||
fieldsToRemove.add(field);
|
||||
}
|
||||
});
|
||||
if (!fieldsToRemove.isEmpty()) {
|
||||
unifiedJedis.hdel("uuid-cache", fieldsToRemove.toArray(new String[0]));
|
||||
}
|
||||
plugin.logInfo("deleted {} entries", fieldsToRemove.size());
|
||||
} catch (JedisException e) {
|
||||
plugin.logFatal("There was an error fetching information", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
||||
import redis.clients.jedis.Protocol;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
|
||||
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("Redis server version: " + version);
|
||||
if (!RedisUtil.isRedisVersionRight(version)) {
|
||||
plugin.logFatal("Your version of Redis (" + version + ") is not at least version " + RedisUtil.MAJOR_VERSION + "." + RedisUtil.MINOR_VERSION + " 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 '/rb clean' to remove expired cache entries");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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 final int MAJOR_VERSION = 6;
|
||||
public static final int MINOR_VERSION = 2;
|
||||
|
||||
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]);
|
||||
|
||||
if (major > MAJOR_VERSION) return true;
|
||||
return major == MAJOR_VERSION && minor >= MINOR_VERSION;
|
||||
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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 MultiMapSerialization {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.JsonObject;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.ResponseBody;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NameFetcher {
|
||||
private static OkHttpClient httpClient;
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public static void setHttpClient(OkHttpClient httpClient) {
|
||||
NameFetcher.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
|
||||
String name = getName(uuid);
|
||||
if (name == null) return Collections.emptyList();
|
||||
return Collections.singletonList(name);
|
||||
}
|
||||
|
||||
public static String getName(UUID uuid) throws IOException {
|
||||
String url = "https://playerdb.co/api/player/minecraft/" + uuid.toString();
|
||||
Request request = new Request.Builder()
|
||||
.addHeader("User-Agent", "RedisBungee-ProxioDev")
|
||||
.url(url)
|
||||
.get()
|
||||
.build();
|
||||
ResponseBody body = httpClient.newCall(request).execute().body();
|
||||
String response = body.string();
|
||||
body.close();
|
||||
|
||||
JsonObject json = gson.fromJson(response, JsonObject.class);
|
||||
if (!json.has("success") || !json.get("success").getAsBoolean()) return null;
|
||||
if (!json.has("data")) return null;
|
||||
JsonObject data = json.getAsJsonObject("data");
|
||||
if (!data.has("player")) return null;
|
||||
JsonObject player = data.getAsJsonObject("player");
|
||||
if (!player.has("username")) return null;
|
||||
|
||||
return player.get("username").getAsString();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal.util.uuid;
|
||||
/*
|
||||
* 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;
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* 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.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.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
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 PlayerDB.
|
||||
String name;
|
||||
try {
|
||||
name = NameFetcher.getName(player);
|
||||
} catch (Exception e) {
|
||||
plugin.logFatal("Unable to fetch name from PlayerDB 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,70 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
|
||||
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 static final String ALREADY_LOGGED_IN = "§cYou are already logged on to this server. \n\nIt may help to try logging in again in a few minutes.\nIf this does not resolve your issue, please contact staff.";
|
||||
|
||||
protected static final String ONLINE_MODE_RECONNECT = "§cWhoops! You need to reconnect\n\nWe found someone online using your username. They were kicked and you may reconnect.\nIf this does not work, please contact staff.";
|
||||
|
||||
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 abstract 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);
|
||||
|
||||
protected 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")
|
||||
protected 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void serializeCollection(Collection<?> collection, ByteArrayDataOutput output) {
|
||||
output.writeInt(collection.size());
|
||||
for (Object o : collection) {
|
||||
output.writeUTF(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onPubSubMessage(PS event);
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
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 redis.clients.jedis.Jedis;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
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 DataManager<P, PL, PD, PS> {
|
||||
private 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 DataManager(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();
|
||||
}
|
||||
|
||||
private final JsonParser parser = new JsonParser();
|
||||
|
||||
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 Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
try (Jedis tmpRsc = plugin.requestJedis()) {
|
||||
return Objects.requireNonNull(tmpRsc.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().getServerId();
|
||||
|
||||
try {
|
||||
return proxyCache.get(uuid, new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
try (Jedis tmpRsc = plugin.requestJedis()) {
|
||||
return Objects.requireNonNull(tmpRsc.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 Callable<InetAddress>() {
|
||||
@Override
|
||||
public InetAddress call() throws Exception {
|
||||
try (Jedis tmpRsc = plugin.requestJedis()) {
|
||||
String result = tmpRsc.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 Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
try (Jedis tmpRsc = plugin.requestJedis()) {
|
||||
String result = tmpRsc.hget("player:" + uuid, "online");
|
||||
return result == null ? -1 : Long.valueOf(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);
|
||||
|
||||
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 = parser.parse(message).getAsJsonObject();
|
||||
|
||||
String source = jsonObject.get("source").getAsString();
|
||||
|
||||
if (source.equals(plugin.getConfiguration().getServerId()))
|
||||
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(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Object event;
|
||||
try {
|
||||
event = plugin.getNetworkJoinEventClass().getDeclaredConstructor(UUID.class).newInstance(message1.getTarget());
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException("unable to dispatch an network join event", e);
|
||||
}
|
||||
plugin.callEvent(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(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Object event;
|
||||
try {
|
||||
event = plugin.getNetworkQuitEventClass().getDeclaredConstructor(UUID.class).newInstance(message2.getTarget());
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException("unable to dispatch an network quit event", e);
|
||||
}
|
||||
plugin.callEvent(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(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Object event;
|
||||
try {
|
||||
event = plugin.getServerChangeEventClass().getDeclaredConstructor(UUID.class, String.class, String.class).newInstance(message3.getTarget(), ((ServerChangePayload) message3.getPayload()).getOldServer(), ((ServerChangePayload) message3.getPayload()).getServer());
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException("unable to dispatch an server change event", e);
|
||||
}
|
||||
plugin.callEvent(event);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DataManagerMessage<T> {
|
||||
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,
|
||||
SERVER_CHANGE
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoginPayload {
|
||||
private final InetAddress address;
|
||||
|
||||
public LoginPayload(InetAddress address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public InetAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerChangePayload{
|
||||
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 {
|
||||
private final long timestamp;
|
||||
|
||||
public LogoutPayload(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
Class<?> getPubSubEventClass();
|
||||
|
||||
Class<?> getNetworkJoinEventClass();
|
||||
|
||||
Class<?> getServerChangeEventClass();
|
||||
|
||||
Class<?> getNetworkQuitEventClass();
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
|
||||
public class JedisPubSubHandler extends JedisPubSub {
|
||||
|
||||
private final RedisBungeePlugin<?> plugin;
|
||||
private final Class<?> eventClass;
|
||||
public JedisPubSubHandler(RedisBungeePlugin<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
this.eventClass = plugin.getPubSubEventClass();
|
||||
}
|
||||
|
||||
@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;
|
||||
try {
|
||||
event = eventClass.getDeclaredConstructor(String.class, String.class).newInstance(s, s2);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException("unable to dispatch an pubsub event", e);
|
||||
}
|
||||
plugin.callEvent(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
|
||||
/**
|
||||
* This class intended for future release to support redis sentinel or redis clusters
|
||||
*
|
||||
* @author Ham1255
|
||||
* @since 0.7.0
|
||||
*
|
||||
*/
|
||||
public interface JedisSummoner {
|
||||
|
||||
Jedis requestJedis();
|
||||
|
||||
boolean isJedisAvailable();
|
||||
|
||||
@Deprecated
|
||||
JedisPool getJedisPool();
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
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() {
|
||||
boolean broken = false;
|
||||
try (Jedis rsc = plugin.requestJedis()) {
|
||||
try {
|
||||
|
||||
jpsh = new JedisPubSubHandler(plugin);
|
||||
addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId());
|
||||
addedChannels.add("redisbungee-allservers");
|
||||
addedChannels.add("redisbungee-data");
|
||||
rsc.subscribe(jpsh, addedChannels.toArray(new String[0]));
|
||||
} catch (Exception e) {
|
||||
// FIXME: Extremely ugly hack
|
||||
// Attempt to unsubscribe this instance and try again.
|
||||
plugin.logWarn("PubSub error, attempting to recover.");
|
||||
try {
|
||||
jpsh.unsubscribe();
|
||||
} catch (Exception e1) {
|
||||
/* This may fail with
|
||||
- java.net.SocketException: Broken pipe
|
||||
- redis.clients.jedis.exceptions.JedisConnectionException: JedisPubSub was not subscribed to a Jedis instance
|
||||
*/
|
||||
}
|
||||
broken = true;
|
||||
}
|
||||
} catch (JedisConnectionException e) {
|
||||
plugin.logWarn("PubSub error, attempting to recover in 5 secs.");
|
||||
plugin.executeAsyncAfter(this, TimeUnit.SECONDS, 5);
|
||||
}
|
||||
|
||||
if (broken) {
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
||||
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,36 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.net.InetAddresses;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
|
||||
public class RedisBungeeConfiguration {
|
||||
private final String serverId;
|
||||
private final List<InetAddress> exemptAddresses;
|
||||
private static RedisBungeeConfiguration config;
|
||||
|
||||
public RedisBungeeConfiguration(String serverId, List<String> exemptAddresses) {
|
||||
this.serverId = serverId;
|
||||
|
||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
||||
for (String s : exemptAddresses) {
|
||||
addressBuilder.add(InetAddresses.forString(s));
|
||||
}
|
||||
this.exemptAddresses = addressBuilder.build();
|
||||
config = this;
|
||||
}
|
||||
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
public List<InetAddress> getExemptAddresses() {
|
||||
return exemptAddresses;
|
||||
}
|
||||
|
||||
public static RedisBungeeConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.UUIDTranslator;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This Class has all internal methods needed by every redis bungee plugin, and it can be used to implement another platforms than bungeecord
|
||||
*
|
||||
* @author Ham1255
|
||||
* @since 0.7.0
|
||||
*
|
||||
*/
|
||||
public interface RedisBungeePlugin<P> extends JedisSummoner, EventsPlatform{
|
||||
|
||||
default void enable() {
|
||||
|
||||
}
|
||||
|
||||
default void disable() {
|
||||
|
||||
}
|
||||
|
||||
RedisBungeeConfiguration getConfiguration();
|
||||
|
||||
int getCount();
|
||||
|
||||
int getCurrentCount();
|
||||
|
||||
Set<String> getLocalPlayersAsUuidStrings();
|
||||
|
||||
DataManager<P, ?, ?, ?> getDataManager();
|
||||
|
||||
Set<UUID> getPlayers();
|
||||
|
||||
RedisBungeeAPI getApi();
|
||||
|
||||
UUIDTranslator getUuidTranslator();
|
||||
|
||||
Multimap<String, UUID> serversToPlayers();
|
||||
|
||||
Set<UUID> getPlayersOnProxy(String proxyId);
|
||||
|
||||
void sendProxyCommand(String serverId, String command);
|
||||
|
||||
List<String> getServerIds();
|
||||
|
||||
List<String > getCurrentServerIds(boolean nag, boolean lagged);
|
||||
|
||||
PubSubListener getPubSubListener();
|
||||
|
||||
void sendChannelMessage(String channel, String message);
|
||||
|
||||
void executeAsync(Runnable runnable);
|
||||
|
||||
void executeAsyncAfter(Runnable runnable, TimeUnit timeUnit, int time);
|
||||
|
||||
void callEvent(Object event);
|
||||
|
||||
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);
|
||||
|
||||
void sendProxyCommand(String cmd);
|
||||
|
||||
long getRedisTime(List<String> timeRes);
|
||||
|
||||
void loadConfig() throws Exception;
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.gson.Gson;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@VisibleForTesting
|
||||
public class RedisUtil {
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public static void cleanUpPlayer(String player, Jedis rsc) {
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player);
|
||||
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
||||
long timestamp = System.currentTimeMillis();
|
||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
||||
rsc.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.LEAVE,
|
||||
new DataManager.LogoutPayload(timestamp))));
|
||||
}
|
||||
|
||||
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player);
|
||||
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
||||
long timestamp = System.currentTimeMillis();
|
||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
||||
rsc.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.LEAVE,
|
||||
new DataManager.LogoutPayload(timestamp))));
|
||||
}
|
||||
|
||||
public static boolean isRedisVersionRight(String redisVersion) {
|
||||
// Need to use >=6.2 to use Lua optimizations.
|
||||
String[] args = redisVersion.split("\\.");
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
int major = Integer.parseInt(args[0]);
|
||||
int minor = Integer.parseInt(args[1]);
|
||||
return major >= 6 && minor >= 0;
|
||||
}
|
||||
|
||||
// Ham1255: i am keeping this if some plugin uses this *IF*
|
||||
@Deprecated
|
||||
public static boolean canUseLua(String redisVersion) {
|
||||
return isRedisVersionRight(redisVersion);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal.util;
|
||||
|
||||
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,58 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal.util;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LuaManager {
|
||||
private final RedisBungeePlugin<?> plugin;
|
||||
|
||||
public LuaManager(RedisBungeePlugin<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Script createScript(String script) {
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
String hash = jedis.scriptLoad(script);
|
||||
return new Script(script, hash);
|
||||
}
|
||||
}
|
||||
|
||||
public class Script {
|
||||
private final String script;
|
||||
private final String hashed;
|
||||
|
||||
public Script(String script, String hashed) {
|
||||
this.script = script;
|
||||
this.hashed = hashed;
|
||||
}
|
||||
|
||||
public String getScript() {
|
||||
return script;
|
||||
}
|
||||
|
||||
public String getHashed() {
|
||||
return hashed;
|
||||
}
|
||||
|
||||
public Object eval(List<String> keys, List<String> args) {
|
||||
Object data;
|
||||
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
try {
|
||||
data = jedis.evalsha(hashed, keys, args);
|
||||
} catch (JedisDataException e) {
|
||||
if (e.getMessage().startsWith("NOSCRIPT")) {
|
||||
data = jedis.eval(script, keys, args);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal.util;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
|
||||
|
||||
public abstract class RedisCallable<T> implements Callable<T>, Runnable {
|
||||
private final RedisBungeePlugin<?> plugin;
|
||||
|
||||
public RedisCallable(RedisBungeePlugin<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T call() {
|
||||
return run(false);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
call();
|
||||
}
|
||||
|
||||
private T run(boolean retry) {
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
return call(jedis);
|
||||
} catch (JedisConnectionException e) {
|
||||
plugin.logFatal("Unable to get connection");
|
||||
|
||||
if (!retry) {
|
||||
// Wait one second before retrying the task
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e1) {
|
||||
throw new RuntimeException("task failed to run", e1);
|
||||
}
|
||||
return run(true);
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("task failed to run");
|
||||
}
|
||||
|
||||
protected abstract T call(Jedis jedis);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal.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;
|
||||
|
||||
public class NameFetcher {
|
||||
private static OkHttpClient httpClient;
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public static void setHttpClient(OkHttpClient httpClient) {
|
||||
NameFetcher.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
|
||||
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;
|
||||
}
|
||||
|
||||
public static class Name {
|
||||
private String name;
|
||||
private long changedToAt;
|
||||
}
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal.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.internal.RedisBungeePlugin;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
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 final 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));
|
||||
}
|
||||
|
||||
// Let's try Redis.
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
String stored = jedis.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()) {
|
||||
jedis.hdel("uuid-cache", player.toLowerCase());
|
||||
// Doesn't hurt to also remove the UUID entry as well.
|
||||
jedis.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(), jedis);
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
} catch (JedisException e) {
|
||||
plugin.logFatal("Unable to fetch UUID for " + player);
|
||||
}
|
||||
|
||||
return null; // Nope, game over!
|
||||
}
|
||||
|
||||
public final 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);
|
||||
}
|
||||
|
||||
// Okay, it wasn't locally cached. Let's try Redis.
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
String stored = jedis.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()) {
|
||||
jedis.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.
|
||||
jedis.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.
|
||||
String name;
|
||||
try {
|
||||
List<String> nameHist = NameFetcher.nameHistoryFromUuid(player);
|
||||
name = Iterables.getLast(nameHist, null);
|
||||
} catch (Exception e) {
|
||||
plugin.logFatal("Unable to fetch name from Mojang for " + player);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
persistInfo(name, player, jedis);
|
||||
return name;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (JedisException e) {
|
||||
plugin.logFatal("Unable to fetch name for " + player);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final void persistInfo(String name, UUID uuid, Jedis jedis) {
|
||||
addToMaps(name, uuid);
|
||||
String json = gson.toJson(uuidToNameMap.get(uuid));
|
||||
jedis.hmset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json));
|
||||
}
|
||||
|
||||
public final void persistInfo(String name, UUID uuid, Pipeline jedis) {
|
||||
addToMaps(name, uuid);
|
||||
String json = gson.toJson(uuidToNameMap.get(uuid));
|
||||
jedis.hmset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json));
|
||||
}
|
||||
|
||||
private static 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
203
RedisBungee-API/src/main/resources/REDISBUNGEE_LICENSE
Normal file
203
RedisBungee-API/src/main/resources/REDISBUNGEE_LICENSE
Normal file
@@ -0,0 +1,203 @@
|
||||
Eclipse Public License - v 1.0
|
||||
|
||||
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
|
||||
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
|
||||
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
||||
|
||||
1. DEFINITIONS
|
||||
|
||||
"Contribution" means:
|
||||
|
||||
a) in the case of the initial Contributor, the initial code and documentation
|
||||
distributed under this Agreement, and
|
||||
b) in the case of each subsequent Contributor:
|
||||
i) changes to the Program, and
|
||||
ii) additions to the Program;
|
||||
|
||||
where such changes and/or additions to the Program originate from and are
|
||||
distributed by that particular Contributor. A Contribution 'originates'
|
||||
from a Contributor if it was added to the Program by such Contributor
|
||||
itself or anyone acting on such Contributor's behalf. Contributions do not
|
||||
include additions to the Program which: (i) are separate modules of
|
||||
software distributed in conjunction with the Program under their own
|
||||
license agreement, and (ii) are not derivative works of the Program.
|
||||
|
||||
"Contributor" means any person or entity that distributes the Program.
|
||||
|
||||
"Licensed Patents" mean patent claims licensable by a Contributor which are
|
||||
necessarily infringed by the use or sale of its Contribution alone or when
|
||||
combined with the Program.
|
||||
|
||||
"Program" means the Contributions distributed in accordance with this
|
||||
Agreement.
|
||||
|
||||
"Recipient" means anyone who receives the Program under this Agreement,
|
||||
including all Contributors.
|
||||
|
||||
2. GRANT OF RIGHTS
|
||||
a) Subject to the terms of this Agreement, each Contributor hereby grants
|
||||
Recipient a non-exclusive, worldwide, royalty-free copyright license to
|
||||
reproduce, prepare derivative works of, publicly display, publicly
|
||||
perform, distribute and sublicense the Contribution of such Contributor,
|
||||
if any, and such derivative works, in source code and object code form.
|
||||
b) Subject to the terms of this Agreement, each Contributor hereby grants
|
||||
Recipient a non-exclusive, worldwide, royalty-free patent license under
|
||||
Licensed Patents to make, use, sell, offer to sell, import and otherwise
|
||||
transfer the Contribution of such Contributor, if any, in source code and
|
||||
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
|
||||
|
||||
A Contributor may choose to distribute the Program in object code form under
|
||||
its own license agreement, provided that:
|
||||
|
||||
a) it complies with the terms and conditions of this Agreement; and
|
||||
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:
|
||||
|
||||
a) it must be made available under this Agreement; and
|
||||
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,
|
||||
if
|
||||
any, in a manner that reasonably allows subsequent Recipients to identify the
|
||||
originator of the Contribution.
|
||||
|
||||
4. COMMERCIAL DISTRIBUTION
|
||||
|
||||
Commercial distributors of software may accept certain responsibilities with
|
||||
respect to end users, business partners and the like. While this license is
|
||||
intended to facilitate the commercial use of the Program, the Contributor who
|
||||
includes the Program in a commercial product offering should do so in a manner
|
||||
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
|
||||
offering, Product X. That Contributor is then a Commercial Contributor. If
|
||||
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
|
||||
|
||||
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. 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
|
||||
|
||||
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
|
||||
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
|
||||
|
||||
If any provision of this Agreement is invalid or unenforceable under
|
||||
applicable law, it shall not affect the validity or enforceability of the
|
||||
remainder of the terms of this Agreement, and without further action by the
|
||||
parties hereto, such provision shall be reformed to the minimum extent
|
||||
necessary to make such provision valid and enforceable.
|
||||
|
||||
If Recipient institutes patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Program itself
|
||||
(excluding combinations of the Program with other software or hardware)
|
||||
infringes such Recipient's patent(s), then such Recipient's rights granted
|
||||
under Section 2(b) shall terminate as of the date such litigation is filed.
|
||||
|
||||
All Recipient's rights under this Agreement shall terminate if it fails to
|
||||
comply with any of the material terms or conditions of this Agreement and does
|
||||
not cure such failure in a reasonable period of time after becoming aware of
|
||||
such noncompliance. If all Recipient's rights under this Agreement terminate,
|
||||
Recipient agrees to cease use and distribution of the Program as soon as
|
||||
reasonably practicable. However, Recipient's obligations under this Agreement
|
||||
and any licenses granted by Recipient relating to the Program shall continue
|
||||
and survive.
|
||||
|
||||
Everyone is permitted to copy and distribute copies of this Agreement, but in
|
||||
order to avoid inconsistency the Agreement is copyrighted and may only be
|
||||
modified in the following manner. The Agreement Steward reserves the right to
|
||||
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
|
||||
intellectual property laws of the United States of America. No party to this
|
||||
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
|
||||
any resulting litigation.
|
||||
142
RedisBungee-API/src/main/resources/config.yml
Normal file
142
RedisBungee-API/src/main/resources/config.yml
Normal file
@@ -0,0 +1,142 @@
|
||||
# RedisBungee configuration file.
|
||||
# Notice:
|
||||
# Redis 7.2.4 is last free and open source Redis version after license change
|
||||
# https://download.redis.io/releases/redis-7.2.4.tar.gz which you have to compile yourself,
|
||||
# unless your package manager still provide it.
|
||||
# Here is The alternatives
|
||||
# - 'ValKey' By linux foundation https://valkey.io/download/
|
||||
# - 'KeyDB' by Snapchat inc https://docs.keydb.dev/docs/download/
|
||||
|
||||
|
||||
# The 'Redis', 'ValKey', 'KeyDB' server you will use.
|
||||
# these settings are ignored when cluster mode is enabled.
|
||||
redis-server: 127.0.0.1
|
||||
redis-port: 6379
|
||||
|
||||
# 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
|
||||
|
||||
# OPTIONAL: if your redis uses acl usernames set the username here. leave empty for no username.
|
||||
redis-username: ""
|
||||
|
||||
# OPTIONAL but recommended: If your Redis server uses AUTH, set the required password.
|
||||
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 network, which helps to separate redisbungee instances on same redis instance.
|
||||
# You can use environment variable 'REDISBUNGEE_NETWORK_ID' to override
|
||||
network-id: "main"
|
||||
|
||||
# An identifier for this BungeeCord / Velocity instance. Will randomly generate if leaving it blank.
|
||||
# You can set Environment variable 'REDISBUNGEE_PROXY_ID' to override
|
||||
proxy-id: "proxy-1"
|
||||
|
||||
# since RedisBungee Internally now uses UnifiedJedis instead of Jedis, JedisPool.
|
||||
# which will break compatibility with old plugins that uses RedisBungee JedisPool
|
||||
# so to mitigate this issue, RedisBungee will create an JedisPool for compatibility reasons.
|
||||
# disabled by default
|
||||
# Automatically disabled when cluster mode is enabled
|
||||
enable-jedis-pool-compatibility: false
|
||||
|
||||
# max connections for the compatibility pool
|
||||
compatibility-max-connections: 3
|
||||
|
||||
# restore old login behavior before 0.9.0 update
|
||||
# enabled by default
|
||||
# when true: when player login and there is old player with same uuid it will get disconnected as result and new player will log in
|
||||
# when false: when a player login but login will fail because old player is still connected.
|
||||
kick-when-online: true
|
||||
|
||||
# enabled by default
|
||||
# this option tells RedisBungee handle motd and set online count, when motd is requested
|
||||
# you can disable this when you want to handle motd yourself, use RedisBungee api to get total players when needed :)
|
||||
handle-motd: true
|
||||
|
||||
# A list of IP addresses for which RedisBungee will not modify the response for, useful for automatic
|
||||
# restart scripts.
|
||||
# Automatically disabled if handle-motd is disabled.
|
||||
exempt-ip-addresses: []
|
||||
|
||||
# disabled by default
|
||||
# RedisBungee will attempt to connect player to last server that was stored.
|
||||
reconnect-to-last-server: false
|
||||
|
||||
# For redis bungee legacy commands
|
||||
# either can be run using '/rbl glist' for example
|
||||
# or if 'install' is set to true '/glist' can be used.
|
||||
# 'install' also overrides the proxy installed commands
|
||||
#
|
||||
# In legacy commands each command got it own permissions since they had it own permission pre new command system,
|
||||
# so it's also applied to subcommands in '/rbl'.
|
||||
commands:
|
||||
# Permission redisbungee.legacy.use
|
||||
redisbungee-legacy:
|
||||
enabled: false
|
||||
subcommands:
|
||||
# Permission redisbungee.command.glist
|
||||
glist:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.find
|
||||
find:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.lastseen
|
||||
lastseen:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.ip
|
||||
ip:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.pproxy
|
||||
pproxy:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.sendtoall
|
||||
sendtoall:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.serverid
|
||||
serverid:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.serverids
|
||||
serverids:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.plist
|
||||
plist:
|
||||
enabled: false
|
||||
install: false
|
||||
# Permission redisbungee.command.use
|
||||
redisbungee:
|
||||
enabled: true
|
||||
|
||||
# Config version DO NOT CHANGE!!!!
|
||||
config-version: 2
|
||||
@@ -1,35 +0,0 @@
|
||||
# RedisBungee configuration file.
|
||||
# PLEASE READ THE WIKI: https://github.com/Limework/RedisBungee/wiki
|
||||
|
||||
# The Redis server you use.
|
||||
# Get Redis from http://redis.io/
|
||||
redis-server: 127.0.0.1
|
||||
redis-port: 6379
|
||||
# OPTIONAL: 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 in redis bungee too!
|
||||
# but there is more configuration needed to work see https://github.com/ProxioDev/RedisBungee/issues/18
|
||||
useSSL: false
|
||||
|
||||
# An identifier for this BungeeCord instance. Will randomly generate if leaving it blank.
|
||||
server-id: "test1"
|
||||
|
||||
# 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.
|
||||
register-bungee-commands: true
|
||||
|
||||
# A list of IP addresses for which RedisBungee will not modify the response for, useful for automatic
|
||||
# restart scripts.
|
||||
exempt-ip-addresses: []
|
||||
55
RedisBungee-API/src/main/resources/lang.yml
Normal file
55
RedisBungee-API/src/main/resources/lang.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
# this config file is for messages / Languages
|
||||
# use MiniMessage format https://docs.advntr.dev/minimessage/format.html
|
||||
# for colors etc... Legacy chat color is not supported.
|
||||
|
||||
# Language codes used in minecraft from the minecraft wiki
|
||||
# example: en-us for american english and ar-sa for arabic
|
||||
|
||||
# all codes can be obtained from link below
|
||||
# from the colum Locale Code -> In-game
|
||||
# NOTE: minecraft wiki shows languages like this `en_us` in config it should be `en-us`
|
||||
# https://minecraft.wiki/w/Language
|
||||
|
||||
# example:
|
||||
# lets assume we want to add arabic language.
|
||||
# messages:
|
||||
# logged-in-other-location:
|
||||
# en-us: "<color:red>You logged in from another location!"
|
||||
# ar-sa: "<color:red>لقد اتصلت من مكان اخر"
|
||||
|
||||
|
||||
# RedisBungee Prefix if ever used.
|
||||
prefix: "<color:red>[<color:yellow>Redis<color:red>Bungee]"
|
||||
|
||||
# en-us is american English, Which is the default language used when a language for a message isn't defined.
|
||||
# Warning: IF THE set default locale wasn't defined in the config for all messages, plugin will not load.
|
||||
# set the Default locale
|
||||
default-locale: en-us
|
||||
|
||||
# send language based on client sent settings
|
||||
# if you don't have languages configured For client Language
|
||||
# it will default to language that has been set above
|
||||
# NOTE: due minecraft protocol not sending player settings during login,
|
||||
# some of the messages like logged-in-other-location will
|
||||
# skip translation and use default locale that has been set in default-locale.
|
||||
use-client-locale: true
|
||||
|
||||
# messages that are used during login, and connecting to Last server
|
||||
messages:
|
||||
logged-in-other-location:
|
||||
en-us: "<color:red>You logged in from another location!"
|
||||
pt-br: "<color:red>Você está logado em outra localização!"
|
||||
already-logged-in:
|
||||
en-us: "<color:red>You are already logged in!"
|
||||
pt-br: "<color:red>Você já está logado!"
|
||||
server-not-found:
|
||||
# placeholder <server> displays server name in the message.
|
||||
en-us: "<color:red>unable to connect you to the last server, because server <server> was not found."
|
||||
pt-br: "<color:red>falha ao conectar você ao último servidor, porque o servidor <server> não foi encontrado."
|
||||
server-connecting:
|
||||
# placeholder <server> displays server name in the message.
|
||||
en-us: "<color:green>Connecting you to <server>..."
|
||||
pt-br: "<color:green>Conectando você a <server>..."
|
||||
|
||||
# DO NOT CHANGE!!!!!
|
||||
config-version: 1
|
||||
@@ -1,24 +0,0 @@
|
||||
local c = redis.call
|
||||
|
||||
local curTime = c("TIME")
|
||||
local time = tonumber(curTime[1])
|
||||
|
||||
local heartbeats = c("HGETALL", "heartbeats")
|
||||
local total = 0
|
||||
local key
|
||||
|
||||
for _, v in ipairs(heartbeats) do
|
||||
if not key then
|
||||
key = v
|
||||
else
|
||||
local n = tonumber(v)
|
||||
if n then
|
||||
if n + 30 >= time then
|
||||
total = total + c("SCARD", "proxy:" .. key .. ":usersOnline")
|
||||
end
|
||||
end
|
||||
key = nil
|
||||
end
|
||||
end
|
||||
|
||||
return total
|
||||
@@ -1,18 +0,0 @@
|
||||
local call = redis.call
|
||||
local ipairs = ipairs
|
||||
|
||||
local serverToData = {}
|
||||
|
||||
for _, proxy in ipairs(ARGV) do
|
||||
local players = call("SMEMBERS", "proxy:" .. proxy .. ":usersOnline")
|
||||
for _, player in ipairs(players) do
|
||||
local server = call("HGET", "player:" .. player, "server")
|
||||
if server then
|
||||
local sz = #serverToData
|
||||
serverToData[sz + 1] = server
|
||||
serverToData[sz + 2] = player
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return serverToData
|
||||
91
RedisBungee-Bungee/build.gradle.kts
Normal file
91
RedisBungee-Bungee/build.gradle.kts
Normal file
@@ -0,0 +1,91 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
||||
id("xyz.jpenilla.run-waterfall") version "2.0.0"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":RedisBungee-API"))
|
||||
compileOnly(libs.platform.bungeecord) {
|
||||
exclude("com.google.guava", "guava")
|
||||
exclude("com.google.code.gson", "gson")
|
||||
exclude("net.kyori","adventure-api")
|
||||
}
|
||||
implementation(libs.adventure.platforms.bungeecord)
|
||||
implementation(libs.adventure.gson)
|
||||
implementation(libs.acf.bungeecord)
|
||||
implementation(project(":RedisBungee-Commands"))
|
||||
}
|
||||
|
||||
description = "RedisBungee Bungeecord implementation"
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
|
||||
tasks {
|
||||
withType<Javadoc> {
|
||||
dependsOn(project(":RedisBungee-API").getTasksByName("javadoc", false))
|
||||
val options = options as StandardJavadocDocletOptions
|
||||
options.use()
|
||||
options.isDocFilesSubDirs = true
|
||||
options.links(
|
||||
"https://ci.md-5.net/job/BungeeCord/ws/api/target/apidocs/", // bungeecord api
|
||||
)
|
||||
val apiDocs = File(rootProject.projectDir, "RedisBungee-API/build/docs/javadoc")
|
||||
options.linksOffline("https://ci.limework.net/RedisBungee/RedisBungee-API/build/docs/javadoc", apiDocs.path)
|
||||
}
|
||||
runWaterfall {
|
||||
waterfallVersion("1.20")
|
||||
environment["REDISBUNGEE_PROXY_ID"] = "bungeecord-1"
|
||||
environment["REDISBUNGEE_NETWORK_ID"] = "dev"
|
||||
}
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.release.set(17)
|
||||
}
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
processResources {
|
||||
filteringCharset = Charsets.UTF_8.name()
|
||||
filesMatching("plugin.yml") {
|
||||
filter {
|
||||
it.replace("*{redisbungee.version}*", "$version", false)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
shadowJar {
|
||||
relocate("redis.clients.jedis", "com.imaginarycode.minecraft.redisbungee.internal.jedis")
|
||||
relocate("redis.clients.util", "com.imaginarycode.minecraft.redisbungee.internal.jedisutil")
|
||||
relocate("org.apache.commons.pool", "com.imaginarycode.minecraft.redisbungee.internal.commonspool")
|
||||
relocate("com.squareup.okhttp", "com.imaginarycode.minecraft.redisbungee.internal.okhttp")
|
||||
relocate("okio", "com.imaginarycode.minecraft.redisbungee.internal.okio")
|
||||
relocate("org.json", "com.imaginarycode.minecraft.redisbungee.internal.json")
|
||||
// configurate shade
|
||||
relocate("ninja.leaping.configurate", "com.imaginarycode.minecraft.redisbungee.internal.configurate")
|
||||
relocate("org.yaml", "com.imaginarycode.minecraft.redisbungee.internal.yml")
|
||||
relocate("com.google.common", "com.imaginarycode.minecraft.redisbungee.internal.com.google.common")
|
||||
relocate("com.google.errorprone", "com.imaginarycode.minecraft.redisbungee.internal.com.google.errorprone")
|
||||
relocate("com.google.gson", "com.imaginarycode.minecraft.redisbungee.internal.com.google.gson")
|
||||
relocate("com.google.j2objc", "com.imaginarycode.minecraft.redisbungee.internal.com.google.j2objc")
|
||||
relocate("com.google.thirdparty", "com.imaginarycode.minecraft.redisbungee.internal.com.google.thirdparty")
|
||||
relocate("com.github.benmanes.caffeine", "com.imaginarycode.minecraft.redisbungee.internal.caffeine")
|
||||
// acf shade
|
||||
relocate("co.aikar.commands", "com.imaginarycode.minecraft.redisbungee.internal.acf.commands")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,122 +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.7.1-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-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>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee-API</artifactId>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee-BungeeEvents</artifactId>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
</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>
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import co.aikar.commands.BungeeCommandIssuer;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.CommandPlatformHelper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
|
||||
public class BungeeCommandPlatformHelper extends CommandPlatformHelper {
|
||||
|
||||
@Override
|
||||
public void sendMessage(CommandIssuer issuer, Component component) {
|
||||
BungeeCommandIssuer bIssuer = (BungeeCommandIssuer) issuer;
|
||||
bIssuer.getIssuer().sendMessage(BungeeComponentSerializer.get().serialize(component));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||
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;
|
||||
|
||||
public class BungeeDataManager extends DataManager<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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.PlayerDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.LoginEvent;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class BungeePlayerDataManager extends PlayerDataManager<ProxiedPlayer, PostLoginEvent, PlayerDisconnectEvent, PubSubMessageEvent, PlayerChangedServerNetworkEvent, PlayerLeftNetworkEvent, ServerConnectedEvent> implements Listener {
|
||||
|
||||
public BungeePlayerDataManager(RedisBungeePlugin<ProxiedPlayer> plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onPlayerChangedServerNetworkEvent(PlayerChangedServerNetworkEvent event) {
|
||||
super.handleNetworkPlayerServerChange(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onNetworkPlayerQuit(PlayerLeftNetworkEvent event) {
|
||||
super.handleNetworkPlayerQuit(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onPubSubMessageEvent(PubSubMessageEvent event) {
|
||||
super.handlePubSubMessageEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onServerConnectedEvent(ServerConnectedEvent event) {
|
||||
final String currentServer = event.getServer().getInfo().getName();
|
||||
final String oldServer = event.getPlayer().getServer() == null ? null : event.getPlayer().getServer().getInfo().getName();
|
||||
super.playerChangedServer(event.getPlayer().getUniqueId(), oldServer, currentServer);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLoginEvent(LoginEvent event) {
|
||||
event.registerIntent((Plugin) plugin);
|
||||
// check if online
|
||||
if (getLastOnline(event.getConnection().getUniqueId()) == 0) {
|
||||
if (plugin.configuration().kickWhenOnline()) {
|
||||
kickPlayer(event.getConnection().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation());
|
||||
// wait 3 seconds before releasing the event
|
||||
plugin.executeAsyncAfter(() -> event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
event.setCancelReason(BungeeComponentSerializer.get().serialize(plugin.langConfiguration().messages().alreadyLoggedIn()));
|
||||
event.completeIntent((Plugin) plugin);
|
||||
}
|
||||
} else {
|
||||
event.completeIntent((Plugin) plugin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onLoginEvent(PostLoginEvent event) {
|
||||
super.addPlayer(event.getPlayer().getUniqueId(), event.getPlayer().getName(), event.getPlayer().getAddress().getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onDisconnectEvent(PlayerDisconnectEvent event) {
|
||||
super.removePlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RBUtils {
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
protected static void createPlayer(ProxiedPlayer player, Pipeline pipeline, boolean fireEvent) {
|
||||
createPlayer(player.getPendingConnection(), pipeline, fireEvent);
|
||||
if (player.getServer() != null)
|
||||
pipeline.hset("player:" + player.getUniqueId().toString(), "server", player.getServer().getInfo().getName());
|
||||
}
|
||||
|
||||
protected static void createPlayer(PendingConnection connection, Pipeline pipeline, boolean fireEvent) {
|
||||
Map<String, String> playerData = new HashMap<>(4);
|
||||
playerData.put("online", "0");
|
||||
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
|
||||
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getServerId());
|
||||
|
||||
pipeline.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", connection.getUniqueId().toString());
|
||||
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
||||
|
||||
if (fireEvent) {
|
||||
pipeline.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
||||
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
|
||||
new DataManager.LoginPayload(connection.getAddress().getAddress()))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* 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 co.aikar.commands.BungeeCommandManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.PlayerDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.ProxyDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.LangConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.loaders.ConfigLoader;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.loaders.LangConfigLoader;
|
||||
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.util.InitialUtils;
|
||||
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.CommandLoader;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.CommandPlatformHelper;
|
||||
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 net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
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 net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetAddress;
|
||||
import java.sql.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlayer>, ConfigLoader, LangConfigLoader {
|
||||
|
||||
private static RedisBungeeAPI apiStatic;
|
||||
private AbstractRedisBungeeAPI api;
|
||||
private RedisBungeeMode redisBungeeMode;
|
||||
private ProxyDataManager proxyDataManager;
|
||||
private BungeePlayerDataManager playerDataManager;
|
||||
private ScheduledTask heartbeatTask;
|
||||
private ScheduledTask cleanupTask;
|
||||
private Summoner<?> summoner;
|
||||
private UUIDTranslator uuidTranslator;
|
||||
private RedisBungeeConfiguration configuration;
|
||||
private LangConfiguration langConfiguration;
|
||||
private OkHttpClient httpClient;
|
||||
private BungeeCommandManager commandManager;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger("RedisBungee");
|
||||
|
||||
|
||||
@Override
|
||||
public RedisBungeeConfiguration configuration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LangConfiguration langConfiguration() {
|
||||
return this.langConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractRedisBungeeAPI getAbstractRedisBungeeApi() {
|
||||
return this.api;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProxyDataManager proxyDataManager() {
|
||||
return this.proxyDataManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDataManager<ProxiedPlayer, ?, ?, ?, ?, ?, ?> playerDataManager() {
|
||||
return this.playerDataManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUIDTranslator getUuidTranslator() {
|
||||
return this.uuidTranslator;
|
||||
}
|
||||
|
||||
@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.logger.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String format, Object... object) {
|
||||
this.logger.info(format, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarn(String msg) {
|
||||
this.logger.warn(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarn(String format, Object... object) {
|
||||
this.logger.warn(format, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logFatal(String msg) {
|
||||
this.logger.error(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logFatal(String format, Throwable throwable) {
|
||||
this.logger.error(format, throwable);
|
||||
}
|
||||
|
||||
@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 boolean handlePlatformKick(UUID uuid, Component message) {
|
||||
ProxiedPlayer player = getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
if (!player.isConnected()) return false;
|
||||
player.disconnect(BungeeComponentSerializer.get().serialize(message));
|
||||
return true;
|
||||
}
|
||||
|
||||
@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() {
|
||||
logInfo("Initializing RedisBungee.....");
|
||||
logInfo("Version: {}", Constants.VERSION);
|
||||
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.WARNING, "skipping replacement.....");
|
||||
}
|
||||
try {
|
||||
loadConfig(this, getDataFolder().toPath());
|
||||
loadLangConfig(this, getDataFolder().toPath());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to load/save config", e);
|
||||
}
|
||||
// init the proxy data manager
|
||||
this.proxyDataManager = new ProxyDataManager(this) {
|
||||
@Override
|
||||
public Set<UUID> getLocalOnlineUUIDs() {
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
ProxyServer.getInstance().getPlayers().forEach((proxiedPlayer) -> uuids.add(proxiedPlayer.getUniqueId()));
|
||||
return uuids;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlatformCommandExecution(String command) {
|
||||
logInfo("Dispatching {}", command);
|
||||
ProxyServer.getInstance().getPluginManager().dispatchCommand(RedisBungeeCommandSender.getSingleton(), command);
|
||||
}
|
||||
};
|
||||
this.playerDataManager = new BungeePlayerDataManager(this);
|
||||
|
||||
getProxy().getPluginManager().registerListener(this, this.playerDataManager);
|
||||
getProxy().getPluginManager().registerListener(this, new RedisBungeeListener(this));
|
||||
// start listening
|
||||
getProxy().getScheduler().runAsync(this, proxyDataManager);
|
||||
// heartbeat
|
||||
this.heartbeatTask = getProxy().getScheduler().schedule(this, () -> this.proxyDataManager.publishHeartbeat(), 0, 1, TimeUnit.SECONDS);
|
||||
// cleanup
|
||||
this.cleanupTask = getProxy().getScheduler().schedule(this, () -> this.proxyDataManager.correctionTask(), 0, 60, TimeUnit.SECONDS);
|
||||
// init the http lib
|
||||
httpClient = new OkHttpClient();
|
||||
Dispatcher dispatcher = new Dispatcher(getExecutorService());
|
||||
httpClient.setDispatcher(dispatcher);
|
||||
NameFetcher.setHttpClient(httpClient);
|
||||
UUIDFetcher.setHttpClient(httpClient);
|
||||
InitialUtils.checkRedisVersion(this);
|
||||
uuidTranslator = new UUIDTranslator(this);
|
||||
|
||||
// register plugin messages channel.
|
||||
getProxy().registerChannel("legacy:redisbungee");
|
||||
getProxy().registerChannel("RedisBungee");
|
||||
|
||||
// init the api
|
||||
this.api = new RedisBungeeAPI(this);
|
||||
apiStatic = (RedisBungeeAPI) this.api;
|
||||
|
||||
// commands
|
||||
CommandPlatformHelper.init(new BungeeCommandPlatformHelper());
|
||||
this.commandManager = new BungeeCommandManager(this);
|
||||
CommandLoader.initCommands(this.commandManager, this);
|
||||
|
||||
logInfo("RedisBungee initialized successfully ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
logInfo("Turning off redis connections.....");
|
||||
getProxy().getPluginManager().unregisterListeners(this);
|
||||
|
||||
if (this.cleanupTask != null) {
|
||||
this.cleanupTask.cancel();
|
||||
}
|
||||
if (heartbeatTask != null) {
|
||||
heartbeatTask.cancel();
|
||||
}
|
||||
try {
|
||||
this.proxyDataManager.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
this.summoner.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (this.commandManager != null) {
|
||||
this.commandManager.unregisterCommands();
|
||||
}
|
||||
logInfo("RedisBungee shutdown successfully");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Summoner<?> getSummoner() {
|
||||
return this.summoner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisBungeeMode getRedisBungeeMode() {
|
||||
return this.redisBungeeMode;
|
||||
}
|
||||
|
||||
@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 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}
|
||||
*
|
||||
* @return the {@link AbstractRedisBungeeAPI} object instance.
|
||||
* @deprecated Please use {@link RedisBungeeAPI#getRedisBungeeApi()} this class intended to for old plugins that no longer updated.
|
||||
*/
|
||||
@Deprecated
|
||||
public static RedisBungeeAPI getApi() {
|
||||
return apiStatic;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public JedisPool getPool() {
|
||||
return api.getJedisPool();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onLangConfigLoad(LangConfiguration langConfiguration) {
|
||||
this.langConfiguration = langConfiguration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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,633 +0,0 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
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.google.common.io.ByteStreams;
|
||||
import com.google.gson.Gson;
|
||||
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.PubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.*;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.IOUtil;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.LuaManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.NameFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.UUIDFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.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 net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
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;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin<ProxiedPlayer> {
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
private RedisBungeeAPI api;
|
||||
private PubSubListener psl = null;
|
||||
private JedisPool jedisPool;
|
||||
private UUIDTranslator uuidTranslator;
|
||||
private RedisBungeeConfiguration configuration;
|
||||
private BungeeDataManager dataManager;
|
||||
private OkHttpClient httpClient;
|
||||
private volatile List<String> serverIds;
|
||||
private final AtomicInteger nagAboutServers = new AtomicInteger();
|
||||
private final AtomicInteger globalPlayerCount = new AtomicInteger();
|
||||
private Future<?> integrityCheck;
|
||||
private Future<?> heartbeatTask;
|
||||
private LuaManager.Script serverToPlayersScript;
|
||||
private LuaManager.Script getPlayerCountScript;
|
||||
|
||||
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 int getCurrentCount() {
|
||||
Long count = (Long) getPlayerCountScript.eval(ImmutableList.<String>of(), ImmutableList.<String>of());
|
||||
return count.intValue();
|
||||
}
|
||||
|
||||
@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 DataManager<ProxiedPlayer, ?, ?, ?> getDataManager() {
|
||||
return this.dataManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
||||
if (isJedisAvailable()) {
|
||||
try (Jedis rsc = requestJedis()) {
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (String i : getServerIds()) {
|
||||
keys.add("proxy:" + i + ":usersOnline");
|
||||
}
|
||||
if (!keys.isEmpty()) {
|
||||
Set<String> users = rsc.sunion(keys.toArray(new String[keys.size()]));
|
||||
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!
|
||||
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||
throw new RuntimeException("Unable to get all players online", e);
|
||||
}
|
||||
}
|
||||
return setBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Jedis requestJedis() {
|
||||
return this.jedisPool.getResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJedisAvailable() {
|
||||
return !jedisPool.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JedisPool getJedisPool() {
|
||||
return this.jedisPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisBungeeAPI getApi() {
|
||||
return this.api;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUIDTranslator getUuidTranslator() {
|
||||
return this.uuidTranslator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Multimap<String, UUID> serversToPlayers() {
|
||||
try {
|
||||
return serverToPlayersCache.get(SERVER_TO_PLAYERS_KEY, new Callable<Multimap<String, UUID>>() {
|
||||
@Override
|
||||
public Multimap<String, UUID> call() throws Exception {
|
||||
Collection<String> data = (Collection<String>) serverToPlayersScript.eval(ImmutableList.<String>of(), getServerIds());
|
||||
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
||||
String key = null;
|
||||
for (String s : data) {
|
||||
if (key == null) {
|
||||
key = s;
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.put(key, UUID.fromString(s));
|
||||
key = null;
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getPlayersOnProxy(String proxyId) {
|
||||
checkArgument(getServerIds().contains(proxyId), proxyId + " is not a valid proxy ID");
|
||||
try (Jedis jedis = requestJedis()) {
|
||||
Set<String> users = jedis.smembers("proxy:" + proxyId + ":usersOnline");
|
||||
ImmutableSet.Builder<UUID> builder = ImmutableSet.builder();
|
||||
for (String user : users) {
|
||||
builder.add(UUID.fromString(user));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendProxyCommand(String serverId, String command) {
|
||||
checkArgument(getServerIds().contains(serverId) || serverId.equals("allservers"), "proxyId is invalid");
|
||||
sendChannelMessage("redisbungee-" + serverId, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServerIds() {
|
||||
return serverIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCurrentServerIds(boolean nag, boolean lagged) {
|
||||
try (Jedis jedis = requestJedis()) {
|
||||
long time = getRedisTime(jedis.time());
|
||||
int nagTime = 0;
|
||||
if (nag) {
|
||||
nagTime = nagAboutServers.decrementAndGet();
|
||||
if (nagTime <= 0) {
|
||||
nagAboutServers.set(10);
|
||||
}
|
||||
}
|
||||
ImmutableList.Builder<String> servers = ImmutableList.builder();
|
||||
Map<String, String> heartbeats = jedis.hgetAll("heartbeats");
|
||||
for (Map.Entry<String, String> entry : heartbeats.entrySet()) {
|
||||
try {
|
||||
long stamp = Long.parseLong(entry.getValue());
|
||||
if (lagged ? time >= stamp + 30 : time <= stamp + 30)
|
||||
servers.add(entry.getKey());
|
||||
else if (nag && nagTime <= 0) {
|
||||
getLogger().warning(entry.getKey() + " is " + (time - stamp) + " seconds behind! (Time not synchronized or server down?) and was removed from heartbeat.");
|
||||
jedis.hdel("heartbeats", entry.getKey());
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
return servers.build();
|
||||
} catch (JedisConnectionException e) {
|
||||
getLogger().log(Level.SEVERE, "Unable to fetch server IDs", e);
|
||||
return Collections.singletonList(configuration.getServerId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PubSubListener getPubSubListener() {
|
||||
return this.psl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChannelMessage(String channel, String message) {
|
||||
try (Jedis jedis = requestJedis()) {
|
||||
jedis.publish(channel, message);
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||
throw new RuntimeException("Unable to publish channel message", e);
|
||||
}
|
||||
}
|
||||
|
||||
@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 callEvent(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 sendProxyCommand(String cmd) {
|
||||
checkArgument(getServerIds().contains(this.configuration.getServerId()) || this.configuration.getServerId().equals("allservers"), "proxyId is invalid");
|
||||
sendChannelMessage("redisbungee-" + this.configuration.getServerId(), cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRedisTime(List<String> timeRes) {
|
||||
return Long.parseLong(timeRes.get(0));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
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();
|
||||
} 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);
|
||||
// call old plugin class to support old plugins
|
||||
new RedisBungee(api);
|
||||
if (isJedisAvailable()) {
|
||||
try (Jedis tmpRsc = requestJedis()) {
|
||||
// This is more portable than INFO <section>
|
||||
String info = tmpRsc.info();
|
||||
for (String s : info.split("\r\n")) {
|
||||
if (s.startsWith("redis_version:")) {
|
||||
String version = s.split(":")[1];
|
||||
getLogger().info(version + " <- redis version");
|
||||
if (!RedisUtil.isRedisVersionRight(version)) {
|
||||
getLogger().warning("Your version of Redis (" + version + ") is not at least version 6.0 RedisBungee requires a newer version of Redis.");
|
||||
throw new RuntimeException("Unsupported Redis version detected");
|
||||
} else {
|
||||
LuaManager manager = new LuaManager(this);
|
||||
serverToPlayersScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/server_to_players.lua")));
|
||||
getPlayerCountScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/get_player_count.lua")));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tmpRsc.hset("heartbeats", configuration.getServerId(), tmpRsc.time().get(0));
|
||||
|
||||
long uuidCacheSize = tmpRsc.hlen("uuid-cache");
|
||||
if (uuidCacheSize > 750000) {
|
||||
getLogger().info("Looks like you have a really big UUID cache! Run https://www.spigotmc.org/resources/redisbungeecleaner.8505/ as soon as possible.");
|
||||
}
|
||||
}
|
||||
serverIds = getCurrentServerIds(true, false);
|
||||
uuidTranslator = new UUIDTranslator(this);
|
||||
heartbeatTask = service.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Jedis rsc = requestJedis()) {
|
||||
long redisTime = getRedisTime(rsc.time());
|
||||
rsc.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
serverIds = getCurrentServerIds(true, false);
|
||||
globalPlayerCount.set(getCurrentCount());
|
||||
} catch (Throwable e) {
|
||||
getLogger().log(Level.SEVERE, "Unable to update data - did your Redis server go away?", e);
|
||||
}
|
||||
}
|
||||
}, 0, 3, TimeUnit.SECONDS);
|
||||
dataManager = new BungeeDataManager(this);
|
||||
// glist command
|
||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand(this));
|
||||
|
||||
|
||||
getProxy().getPluginManager().registerListener(this, new RedisBungeeListener(this, configuration.getExemptAddresses()));
|
||||
getProxy().getPluginManager().registerListener(this, dataManager);
|
||||
psl = new PubSubListener(this);
|
||||
getProxy().getScheduler().runAsync(this, psl);
|
||||
integrityCheck = service.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Jedis tmpRsc = requestJedis()) {
|
||||
Set<String> players = getLocalPlayersAsUuidStrings();
|
||||
Set<String> playersInRedis = tmpRsc.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
||||
List<String> lagged = getCurrentServerIds(false, true);
|
||||
|
||||
// Clean up lagged players.
|
||||
for (String s : lagged) {
|
||||
Set<String> laggedPlayers = tmpRsc.smembers("proxy:" + s + ":usersOnline");
|
||||
tmpRsc.del("proxy:" + s + ":usersOnline");
|
||||
if (!laggedPlayers.isEmpty()) {
|
||||
getLogger().info("Cleaning up lagged proxy " + s + " (" + laggedPlayers.size() + " players)...");
|
||||
for (String laggedPlayer : laggedPlayers) {
|
||||
RedisUtil.cleanUpPlayer(laggedPlayer, tmpRsc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 : getServerIds()) {
|
||||
if (proxyId.equals(configuration.getServerId())) continue;
|
||||
if (tmpRsc.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
||||
// Just clean up the set.
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
||||
getLogger().warning("Player found in set that was not found locally and globally: " + member);
|
||||
} else {
|
||||
tmpRsc.srem("proxy:" + configuration.getServerId() + ":usersOnline", member);
|
||||
getLogger().warning("Player found in set that was not found locally, but is on another proxy: " + member);
|
||||
}
|
||||
}
|
||||
|
||||
Pipeline pipeline = tmpRsc.pipelined();
|
||||
|
||||
for (String player : absentInRedis) {
|
||||
// Player not online according to Redis but not BungeeCord.
|
||||
getLogger().warning("Player " + player + " is on the proxy but not in Redis.");
|
||||
|
||||
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(UUID.fromString(player));
|
||||
if (proxiedPlayer == null)
|
||||
continue; // We'll deal with it later.
|
||||
|
||||
RBUtils.createPlayer(proxiedPlayer, pipeline, true);
|
||||
}
|
||||
|
||||
pipeline.sync();
|
||||
} catch (Throwable e) {
|
||||
getLogger().log(Level.SEVERE, "Unable to fix up stored player data", e);
|
||||
}
|
||||
}
|
||||
}, 0, 1, TimeUnit.MINUTES);
|
||||
}
|
||||
getProxy().registerChannel("legacy:redisbungee");
|
||||
getProxy().registerChannel("RedisBungee");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if (isJedisAvailable()) {
|
||||
// Poison the PubSub listener
|
||||
psl.poison();
|
||||
integrityCheck.cancel(true);
|
||||
heartbeatTask.cancel(true);
|
||||
getProxy().getPluginManager().unregisterListeners(this);
|
||||
|
||||
try (Jedis tmpRsc = requestJedis()) {
|
||||
tmpRsc.hdel("heartbeats", configuration.getServerId());
|
||||
if (tmpRsc.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
|
||||
Set<String> players = tmpRsc.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
||||
for (String member : players)
|
||||
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
||||
}
|
||||
}
|
||||
|
||||
this.jedisPool.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig() throws IOException {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
File file = new File(getDataFolder(), "config.yml");
|
||||
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
try (InputStream in = getResourceAsStream("example_config.yml");
|
||||
OutputStream out = new FileOutputStream(file)) {
|
||||
ByteStreams.copy(in, out);
|
||||
}
|
||||
}
|
||||
|
||||
final Configuration yamlConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||
|
||||
final String redisServer = yamlConfiguration.getString("redis-server", "localhost");
|
||||
final int redisPort = yamlConfiguration.getInt("redis-port", 6379);
|
||||
final boolean useSSL = yamlConfiguration.getBoolean("useSSL", false);
|
||||
String redisPassword = yamlConfiguration.getString("redis-password", "");
|
||||
String serverId = yamlConfiguration.getString("server-id");
|
||||
final String randomUUID = UUID.randomUUID().toString();
|
||||
|
||||
// check redis password
|
||||
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
||||
redisPassword = null;
|
||||
getLogger().warning("INSECURE setup was detected Please set password for your redis instance.");
|
||||
}
|
||||
if (!useSSL) {
|
||||
getLogger().warning("INSECURE setup was detected Please setup ssl for your redis instance.");
|
||||
}
|
||||
// Configuration sanity checks.
|
||||
if (serverId == null || serverId.isEmpty()) {
|
||||
/*
|
||||
* this check causes the config comments to disappear somehow
|
||||
* I think due snake yaml limitations so as todo: write our own yaml parser?
|
||||
*/
|
||||
String genId = UUID.randomUUID().toString();
|
||||
getLogger().info("Generated server id " + genId + " and saving it to config.");
|
||||
yamlConfiguration.set("server-id", genId);
|
||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(yamlConfiguration, new File(getDataFolder(), "config.yml"));
|
||||
getLogger().info("Server id was generated: " + serverId);
|
||||
} else {
|
||||
getLogger().info("Loaded server id " + serverId + '.');
|
||||
}
|
||||
this.configuration = new RedisBungeeConfiguration(serverId, yamlConfiguration.getStringList("exempt-ip-addresses"));
|
||||
|
||||
if (redisServer != null && !redisServer.isEmpty()) {
|
||||
try {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setMaxTotal(yamlConfiguration.getInt("max-redis-connections", 8));
|
||||
this.jedisPool = new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL);
|
||||
|
||||
} catch (JedisConnectionException e) {
|
||||
throw new RuntimeException("Unable to create Redis pool", e);
|
||||
}
|
||||
|
||||
// Test the connection
|
||||
try (Jedis rsc = requestJedis()) {
|
||||
rsc.ping();
|
||||
// If that worked, now we can check for an existing, alive Bungee:
|
||||
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
||||
if (crashFile.exists()) {
|
||||
crashFile.delete();
|
||||
} else if (rsc.hexists("heartbeats", serverId)) {
|
||||
try {
|
||||
long value = Long.parseLong(rsc.hget("heartbeats", serverId));
|
||||
long redisTime = getRedisTime(rsc.time());
|
||||
if (redisTime < value + 20) {
|
||||
getLogger().severe("You have launched a possible impostor BungeeCord instance. Another instance is already running.");
|
||||
getLogger().severe("For data consistency reasons, RedisBungee will now disable itself.");
|
||||
getLogger().severe("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.");
|
||||
throw new RuntimeException("Possible impostor instance!");
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
httpClient = new OkHttpClient();
|
||||
Dispatcher dispatcher = new Dispatcher(getExecutorService());
|
||||
httpClient.setDispatcher(dispatcher);
|
||||
NameFetcher.setHttpClient(httpClient);
|
||||
UUIDFetcher.setHttpClient(httpClient);
|
||||
|
||||
getLogger().log(Level.INFO, "Successfully connected to Redis.");
|
||||
} catch (JedisConnectionException e) {
|
||||
this.jedisPool.destroy();
|
||||
this.jedisPool = null;
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("No redis server specified!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getPubSubEventClass() {
|
||||
return PubSubMessageEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getNetworkJoinEventClass() {
|
||||
return PlayerJoinedNetworkEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getServerChangeEventClass() {
|
||||
return PlayerChangedServerNetworkEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getNetworkQuitEventClass() {
|
||||
return PlayerJoinedNetworkEvent.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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,3 +1,13 @@
|
||||
/*
|
||||
* 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;
|
||||
@@ -6,143 +16,42 @@ 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.internal.AbstractRedisBungeeListener;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisUtil;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.RedisCallable;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.event.*;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
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.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
|
||||
public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent, PostLoginEvent, PlayerDisconnectEvent, ServerConnectedEvent, ProxyPingEvent, PluginMessageEvent, PubSubMessageEvent> implements Listener {
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.MultiMapSerialization.*;
|
||||
|
||||
public class RedisBungeeListener implements Listener {
|
||||
|
||||
public RedisBungeeListener(RedisBungeePlugin<?> plugin, List<InetAddress> exemptAddresses) {
|
||||
super(plugin, exemptAddresses);
|
||||
private final RedisBungeePlugin<ProxiedPlayer> plugin;
|
||||
|
||||
public RedisBungeeListener(RedisBungeePlugin<ProxiedPlayer> plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onLogin(LoginEvent event) {
|
||||
event.registerIntent((Plugin) plugin);
|
||||
plugin.executeAsync(new RedisCallable<Void>(plugin) {
|
||||
@Override
|
||||
protected Void call(Jedis jedis) {
|
||||
try {
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// We make sure they aren't trying to use an existing player's name.
|
||||
// This is problematic for online-mode servers as they always disconnect old clients.
|
||||
if (plugin.isOnlineMode()) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) plugin.getPlayer(event.getConnection().getName());
|
||||
|
||||
if (player != null) {
|
||||
event.setCancelled(true);
|
||||
// TODO: Make it accept a BaseComponent[] like everything else.
|
||||
event.setCancelReason(ONLINE_MODE_RECONNECT);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : plugin.getServerIds()) {
|
||||
if (jedis.sismember("proxy:" + s + ":usersOnline", event.getConnection().getUniqueId().toString())) {
|
||||
event.setCancelled(true);
|
||||
// TODO: Make it accept a BaseComponent[] like everything else.
|
||||
event.setCancelReason(ALREADY_LOGGED_IN);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
event.completeIntent((Plugin) plugin);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
plugin.executeAsync(new RedisCallable<Void>(plugin) {
|
||||
@Override
|
||||
protected Void call(Jedis jedis) {
|
||||
// this code was moved out from login event due being async..
|
||||
// and it can be cancelled but it will show as false in redis-bungee
|
||||
// which will register the player into the redis database.
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), pipeline);
|
||||
RBUtils.createPlayer(event.getPlayer(), pipeline, false);
|
||||
pipeline.sync();
|
||||
// the end of moved code.
|
||||
|
||||
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage(
|
||||
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
|
||||
new DataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onPlayerDisconnect(PlayerDisconnectEvent event) {
|
||||
plugin.executeAsync(new RedisCallable<Void>(plugin) {
|
||||
@Override
|
||||
protected Void call(Jedis jedis) {
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
RedisUtil.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onServerChange(ServerConnectedEvent event) {
|
||||
final String currentServer = event.getPlayer().getServer() == null ? null : event.getPlayer().getServer().getInfo().getName();
|
||||
plugin.executeAsync(new RedisCallable<Void>(plugin) {
|
||||
@Override
|
||||
protected Void call(Jedis jedis) {
|
||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
||||
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage(
|
||||
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
||||
new DataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onPing(ProxyPingEvent event) {
|
||||
if (exemptAddresses.contains(event.getConnection().getAddress().getAddress())) {
|
||||
return;
|
||||
}
|
||||
if (!plugin.configuration().handleMotd()) return;
|
||||
if (plugin.configuration().getExemptAddresses().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());
|
||||
if (forced != null && event.getConnection().getListener().isPingPassthrough()) return;
|
||||
event.getResponse().getPlayers().setOnline(plugin.proxyDataManager().totalNetworkPlayers());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@EventHandler
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
@@ -157,16 +66,17 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
||||
String type;
|
||||
|
||||
switch (subchannel) {
|
||||
case "PlayerList":
|
||||
case "PlayerList" -> {
|
||||
out.writeUTF("PlayerList");
|
||||
Set<UUID> original = Collections.emptySet();
|
||||
type = in.readUTF();
|
||||
if (type.equals("ALL")) {
|
||||
out.writeUTF("ALL");
|
||||
original = plugin.getPlayers();
|
||||
original = plugin.proxyDataManager().networkPlayers();
|
||||
} else {
|
||||
out.writeUTF(type);
|
||||
try {
|
||||
original = plugin.getApi().getPlayersOnServer(type);
|
||||
original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -174,49 +84,42 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
||||
for (UUID uuid : original)
|
||||
players.add(plugin.getUuidTranslator().getNameFromUuid(uuid, false));
|
||||
out.writeUTF(Joiner.on(',').join(players));
|
||||
break;
|
||||
case "PlayerCount":
|
||||
}
|
||||
case "PlayerCount" -> {
|
||||
out.writeUTF("PlayerCount");
|
||||
type = in.readUTF();
|
||||
if (type.equals("ALL")) {
|
||||
out.writeUTF("ALL");
|
||||
out.writeInt(plugin.getCount());
|
||||
out.writeInt(plugin.proxyDataManager().totalNetworkPlayers());
|
||||
} else {
|
||||
out.writeUTF(type);
|
||||
try {
|
||||
out.writeInt(plugin.getApi().getPlayersOnServer(type).size());
|
||||
out.writeInt(plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type).size());
|
||||
} catch (IllegalArgumentException e) {
|
||||
out.writeInt(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "LastOnline":
|
||||
}
|
||||
case "LastOnline" -> {
|
||||
String user = in.readUTF();
|
||||
out.writeUTF("LastOnline");
|
||||
out.writeUTF(user);
|
||||
out.writeLong(plugin.getApi().getLastOnline(plugin.getUuidTranslator().getTranslatedUuid(user, true)));
|
||||
break;
|
||||
case "ServerPlayers":
|
||||
out.writeLong(plugin.getAbstractRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
||||
}
|
||||
case "ServerPlayers" -> {
|
||||
String type1 = in.readUTF();
|
||||
out.writeUTF("ServerPlayers");
|
||||
Multimap<String, UUID> multimap = plugin.getApi().getServerToPlayers();
|
||||
|
||||
Multimap<String, UUID> multimap = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
||||
boolean includesUsers;
|
||||
|
||||
switch (type1) {
|
||||
case "COUNT":
|
||||
includesUsers = false;
|
||||
break;
|
||||
case "PLAYERS":
|
||||
includesUsers = true;
|
||||
break;
|
||||
default:
|
||||
case "COUNT" -> includesUsers = false;
|
||||
case "PLAYERS" -> includesUsers = true;
|
||||
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()) {
|
||||
@@ -226,19 +129,20 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
||||
} else {
|
||||
serializeMultiset(multimap.keys(), out);
|
||||
}
|
||||
break;
|
||||
case "Proxy":
|
||||
}
|
||||
case "Proxy" -> {
|
||||
out.writeUTF("Proxy");
|
||||
out.writeUTF(plugin.getConfiguration().getServerId());
|
||||
break;
|
||||
case "PlayerProxy":
|
||||
out.writeUTF(plugin.configuration().getProxyId());
|
||||
}
|
||||
case "PlayerProxy" -> {
|
||||
String username = in.readUTF();
|
||||
out.writeUTF("PlayerProxy");
|
||||
out.writeUTF(username);
|
||||
out.writeUTF(plugin.getApi().getProxy(plugin.getUuidTranslator().getTranslatedUuid(username, true)));
|
||||
break;
|
||||
default:
|
||||
out.writeUTF(plugin.getAbstractRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
||||
}
|
||||
default -> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
((Server) event.getSender()).sendData(currentChannel, out.toByteArray());
|
||||
@@ -246,15 +150,19 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
||||
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getApi().getServerId())) {
|
||||
String message = event.getMessage();
|
||||
if (message.startsWith("/"))
|
||||
message = message.substring(1);
|
||||
plugin.logInfo("Invoking command via PubSub: /" + message);
|
||||
plugin.sendProxyCommand(message);
|
||||
public void onServerConnectEvent(ServerConnectEvent event) {
|
||||
if (event.getReason() == ServerConnectEvent.Reason.JOIN_PROXY && plugin.configuration().handleReconnectToLastServer()) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
String lastServer = plugin.playerDataManager().getLastServerFor(event.getPlayer().getUniqueId());
|
||||
if (lastServer == null) return;
|
||||
player.sendMessage(BungeeComponentSerializer.get().serialize(plugin.langConfiguration().messages().serverConnecting(player.getLocale(), lastServer)));
|
||||
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(lastServer);
|
||||
if (serverInfo == null) {
|
||||
player.sendMessage(BungeeComponentSerializer.get().serialize(plugin.langConfiguration().messages().serverNotFound(player.getLocale(), lastServer)));
|
||||
return;
|
||||
}
|
||||
event.setTarget(serverInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
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.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||
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.plugin.Command;
|
||||
|
||||
import java.util.Map;
|
||||
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 RedisBungeeAPI}.
|
||||
*
|
||||
* @author tuxed
|
||||
* @since 0.2.3
|
||||
*/
|
||||
public class RedisBungeeCommands {
|
||||
|
||||
private static String playerPlural(int num) {
|
||||
return num == 1 ? num + " player is" : num + " players are";
|
||||
}
|
||||
|
||||
public static class GlistCommand extends Command {
|
||||
private final RedisBungeePlugin<?> plugin;
|
||||
|
||||
public GlistCommand(RedisBungeePlugin<?> plugin) {
|
||||
super("glist", "bungeecord.command.list", "redisbungee", "rglist");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
plugin.executeAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int count = plugin.getApi().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.getApi().getServerToPlayers();
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
|
||||
human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false));
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,16 @@
|
||||
/*
|
||||
* 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;
|
||||
@@ -13,7 +24,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @since 0.3.4
|
||||
*/
|
||||
public class PlayerChangedServerNetworkEvent extends Event {
|
||||
public class PlayerChangedServerNetworkEvent extends Event implements IPlayerChangedServerNetworkEvent {
|
||||
private final UUID uuid;
|
||||
private final String previousServer;
|
||||
private final String server;
|
||||
@@ -24,14 +35,17 @@ public class PlayerChangedServerNetworkEvent extends Event {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreviousServer() {
|
||||
return previousServer;
|
||||
}
|
||||
@@ -1,5 +1,16 @@
|
||||
/*
|
||||
* 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;
|
||||
@@ -13,13 +24,14 @@ import java.util.UUID;
|
||||
*
|
||||
* @since 0.3.4
|
||||
*/
|
||||
public class PlayerJoinedNetworkEvent extends Event {
|
||||
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,5 +1,16 @@
|
||||
/*
|
||||
* 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;
|
||||
@@ -13,13 +24,14 @@ import java.util.UUID;
|
||||
*
|
||||
* @since 0.3.4
|
||||
*/
|
||||
public class PlayerLeftNetworkEvent extends Event {
|
||||
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,5 +1,16 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@@ -10,7 +21,7 @@ import net.md_5.bungee.api.plugin.Event;
|
||||
* @since 0.2.6
|
||||
*/
|
||||
|
||||
public class PubSubMessageEvent extends Event {
|
||||
public class PubSubMessageEvent extends Event implements IPubSubMessageEvent {
|
||||
private final String channel;
|
||||
private final String message;
|
||||
|
||||
@@ -19,10 +30,12 @@ public class PubSubMessageEvent extends Event {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
name: RedisBungee
|
||||
main: com.imaginarycode.minecraft.redisbungee.RedisBungeeBungeePlugin
|
||||
version: ${project.version}
|
||||
author: Chunkr and Govindas limework
|
||||
authors:
|
||||
- chunkr
|
||||
- Govindas Limework
|
||||
main: com.imaginarycode.minecraft.redisbungee.RedisBungee
|
||||
version: *{redisbungee.version}*
|
||||
author: "astei, ProxioDev"
|
||||
# This is used so that we can automatically override default BungeeCord behavior.
|
||||
softDepends: ["cmd_find", "cmd_list"]
|
||||
@@ -1,52 +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.7.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>RedisBungee-BungeeEvents</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>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<reportOutputDirectory>../javadoc</reportOutputDirectory>
|
||||
<destDir>${project.name}</destDir>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<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>
|
||||
24
RedisBungee-Commands/build.gradle.kts
Normal file
24
RedisBungee-Commands/build.gradle.kts
Normal file
@@ -0,0 +1,24 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":RedisBungee-API"))
|
||||
implementation(libs.acf.core)
|
||||
}
|
||||
|
||||
description = "RedisBungee common commands"
|
||||
|
||||
|
||||
tasks {
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.release.set(17)
|
||||
}
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
processResources {
|
||||
filteringCharset = Charsets.UTF_8.name()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 co.aikar.commands.CommandManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.legacy.LegacyRedisBungeeCommands;
|
||||
|
||||
public class CommandLoader {
|
||||
|
||||
public static void initCommands(CommandManager<?, ?, ?, ?, ?, ?> commandManager, RedisBungeePlugin<?> plugin) {
|
||||
var commandsConfiguration = plugin.configuration().commandsConfiguration();
|
||||
if (commandsConfiguration.redisbungeeEnabled()) {
|
||||
commandManager.registerCommand(new CommandRedisBungee(plugin));
|
||||
}
|
||||
if (commandsConfiguration.redisbungeeLegacyEnabled()) {
|
||||
commandManager.registerCommand(new LegacyRedisBungeeCommands(commandManager,plugin));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* 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 co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.RegisteredCommand;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.imaginarycode.minecraft.redisbungee.Constants;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.AdventureBaseCommand;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.StopperUUIDCleanupTask;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@CommandAlias("rb|redisbungee")
|
||||
@CommandPermission("redisbungee.command.use")
|
||||
@Description("Main command")
|
||||
public class CommandRedisBungee extends AdventureBaseCommand {
|
||||
|
||||
private final RedisBungeePlugin<?> plugin;
|
||||
|
||||
public CommandRedisBungee(RedisBungeePlugin<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
@Subcommand("info|version|git")
|
||||
@Description("information about current redisbungee build")
|
||||
public void info(CommandIssuer issuer) {
|
||||
final String message = """
|
||||
<color:aqua>This proxy is running RedisBungee Limework's fork
|
||||
<color:gold>========================================
|
||||
<color:aqua>RedisBungee version: <color:green><version>
|
||||
<color:aqua>Commit: <color:green><commit>
|
||||
<color:gold>========================================
|
||||
<color:gold>run /rb help for more commands""";
|
||||
sendMessage(
|
||||
issuer,
|
||||
MiniMessage.miniMessage()
|
||||
.deserialize(
|
||||
message,
|
||||
Placeholder.component("version", Component.text(Constants.VERSION)),
|
||||
Placeholder.component(
|
||||
"commit",
|
||||
Component.text(Constants.GIT_COMMIT.substring(0, 8))
|
||||
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, Constants.getGithubCommitLink()))
|
||||
.hoverEvent(HoverEvent.showText(Component.text("Click me to open: " + Constants.getGithubCommitLink())))
|
||||
)));
|
||||
}
|
||||
// <color:aqua>......: <color:green>......
|
||||
@HelpCommand
|
||||
@Description("shows the help page")
|
||||
public void help(CommandIssuer issuer) {
|
||||
final String barFormat = "<color:gold>========================================";
|
||||
final String commandFormat = "<color:aqua>/rb <sub-command>: <color:green><description>";
|
||||
|
||||
TextComponent.Builder message = Component.text();
|
||||
message.append(MiniMessage.miniMessage().deserialize(barFormat));
|
||||
|
||||
getSubCommands().forEach((subCommand, registeredCommand) -> {
|
||||
String[] split = registeredCommand.getCommand().split(" ");
|
||||
if (split.length > 1 && subCommand.equalsIgnoreCase(split[1])) {
|
||||
message.appendNewline().append(MiniMessage.miniMessage().deserialize(commandFormat, Placeholder.component("sub-command", Component.text(subCommand)),
|
||||
Placeholder.component("description", MiniMessage.miniMessage().deserialize(registeredCommand.getHelpText()))
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
message.appendNewline().append(MiniMessage.miniMessage().deserialize(barFormat));
|
||||
|
||||
sendMessage(issuer, message.build());
|
||||
}
|
||||
@Subcommand("clean")
|
||||
@Description("cleans up the uuid cache<color:red> <bold>WARNING...</bold> <color:white>command above could cause performance issues")
|
||||
@Private
|
||||
public void cleanUp(CommandIssuer issuer) {
|
||||
if (StopperUUIDCleanupTask.isRunning) {
|
||||
sendMessage(issuer,
|
||||
Component.text("cleanup is currently running!").color(NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
sendMessage(issuer,
|
||||
Component.text("cleanup is Starting, you should see the output status in the proxy console").color(NamedTextColor.GOLD));
|
||||
plugin.executeAsync(new StopperUUIDCleanupTask(plugin));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<Map.Entry<String, Integer>> subListProxies(List<Map.Entry<String, Integer>> data, final int currentPage, final int pageSize) {
|
||||
return data.subList(((currentPage * pageSize) - pageSize), Ints.constrainToRange(currentPage * pageSize, 0, data.size()));
|
||||
|
||||
}
|
||||
@Subcommand("show")
|
||||
@Description("Shows proxies in this network")
|
||||
public void showProxies(CommandIssuer issuer, String[] args) {
|
||||
final String closer = "<color:gold>========================================";
|
||||
final String pageTop = "<color:yellow>Page: <color:green><current>/<max> <color:yellow>Network ID: <color:green><network> <color:yellow>Proxies online: <color:green><proxies>";
|
||||
final String proxy = "<color:yellow><proxy><here> : <color:green><players> online";
|
||||
final String proxyHere = " (#) ";
|
||||
final String nextPage = ">>>>>";
|
||||
final String previousPage = "<<<<< ";
|
||||
final String pageInvalid = "<color:red>invalid page";
|
||||
final String noProxies = "<color:red>No proxies were found :(";
|
||||
|
||||
final int pageSize = 16;
|
||||
|
||||
int currentPage;
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
currentPage = Integer.parseInt(args[0]);
|
||||
if (currentPage < 1) currentPage = 1;
|
||||
} catch (NumberFormatException e) {
|
||||
sendMessage(issuer, MiniMessage.miniMessage().deserialize(pageInvalid));
|
||||
return;
|
||||
}
|
||||
} else currentPage = 1;
|
||||
|
||||
var data = new ArrayList<>(plugin.proxyDataManager().eachProxyCount().entrySet());
|
||||
// there is no way this runs because there is always an heartbeat.
|
||||
// if not could be some shenanigans done by devs :P
|
||||
if (data.isEmpty()) {
|
||||
sendMessage(issuer, MiniMessage.miniMessage().deserialize(noProxies));
|
||||
return;
|
||||
}
|
||||
// compute the total pages
|
||||
int maxPages = (int) Math.ceil(data.size() / (double) pageSize);
|
||||
if (currentPage > maxPages) currentPage = maxPages;
|
||||
var subList = subListProxies(data, currentPage, pageSize);
|
||||
TextComponent.Builder builder = Component.text();
|
||||
builder.append(MiniMessage.miniMessage().deserialize(closer)).appendNewline();
|
||||
builder.append(MiniMessage.miniMessage().deserialize(pageTop,
|
||||
Placeholder.component("current", Component.text(currentPage)),
|
||||
Placeholder.component("max", Component.text(maxPages)),
|
||||
Placeholder.component("network", Component.text(plugin.proxyDataManager().networkId())),
|
||||
Placeholder.component("proxies", Component.text(data.size()))
|
||||
|
||||
|
||||
)).appendNewline();
|
||||
int left = pageSize;
|
||||
for (Map.Entry<String, Integer> entrySet : subList) {
|
||||
builder.append(MiniMessage.miniMessage().deserialize(proxy,
|
||||
|
||||
Placeholder.component("proxy", Component.text(entrySet.getKey())),
|
||||
Placeholder.component("here", Component.text(plugin.proxyDataManager().proxyId().equals(entrySet.getKey()) ? proxyHere : "")),
|
||||
Placeholder.component("players", Component.text(entrySet.getValue()))
|
||||
|
||||
)).appendNewline();
|
||||
left--;
|
||||
}
|
||||
while(left > 0) {
|
||||
builder.appendNewline();
|
||||
left--;
|
||||
}
|
||||
if (currentPage > 1) {
|
||||
builder.append(MiniMessage.miniMessage().deserialize(previousPage)
|
||||
.color(NamedTextColor.WHITE).clickEvent(ClickEvent.runCommand("/rb show " + (currentPage - 1))));
|
||||
} else {
|
||||
builder.append(MiniMessage.miniMessage().deserialize(previousPage).color(NamedTextColor.GRAY));
|
||||
}
|
||||
if (subList.size() == pageSize && !subListProxies(data, currentPage + 1, pageSize).isEmpty()) {
|
||||
builder.append(MiniMessage.miniMessage().deserialize(nextPage)
|
||||
.color(NamedTextColor.WHITE).clickEvent(ClickEvent.runCommand("/rb show " + (currentPage + 1))));
|
||||
} else {
|
||||
builder.append(MiniMessage.miniMessage().deserialize(nextPage).color(NamedTextColor.GRAY));
|
||||
}
|
||||
builder.appendNewline();
|
||||
builder.append(MiniMessage.miniMessage().deserialize(closer));
|
||||
sendMessage(issuer, builder.build());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.legacy;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.AdventureBaseCommand;
|
||||
|
||||
@CommandAlias("find|rfind")
|
||||
@CommandPermission("redisbungee.command.find")
|
||||
public class CommandFind extends AdventureBaseCommand {
|
||||
|
||||
private final LegacyRedisBungeeCommands rootCommand;
|
||||
|
||||
public CommandFind(LegacyRedisBungeeCommands rootCommand) {
|
||||
this.rootCommand = rootCommand;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void find(CommandIssuer issuer, String[] args) {
|
||||
rootCommand.find(issuer, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.legacy;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.AdventureBaseCommand;
|
||||
|
||||
@CommandAlias("glist|rglist")
|
||||
@CommandPermission("redisbungee.command.glist")
|
||||
public class CommandGList extends AdventureBaseCommand {
|
||||
|
||||
private final LegacyRedisBungeeCommands rootCommand;
|
||||
|
||||
public CommandGList(LegacyRedisBungeeCommands rootCommand) {
|
||||
this.rootCommand = rootCommand;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void gList(CommandIssuer issuer, String[] args) {
|
||||
rootCommand.gList(issuer, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.legacy;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.AdventureBaseCommand;
|
||||
|
||||
@CommandAlias("ip|playerip|rip|rplayerip")
|
||||
@CommandPermission("redisbungee.command.ip")
|
||||
public class CommandIp extends AdventureBaseCommand {
|
||||
|
||||
private final LegacyRedisBungeeCommands rootCommand;
|
||||
|
||||
public CommandIp(LegacyRedisBungeeCommands rootCommand) {
|
||||
this.rootCommand = rootCommand;
|
||||
}
|
||||
|
||||
|
||||
@Default
|
||||
public void ip(CommandIssuer issuer, String[] args) {
|
||||
this.rootCommand.ip(issuer, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.legacy;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.AdventureBaseCommand;
|
||||
|
||||
@CommandAlias("lastseen|rlastseend")
|
||||
@CommandPermission("redisbungee.command.lastseen")
|
||||
public class CommandLastSeen extends AdventureBaseCommand {
|
||||
|
||||
|
||||
private final LegacyRedisBungeeCommands rootCommand;
|
||||
|
||||
public CommandLastSeen(LegacyRedisBungeeCommands rootCommand) {
|
||||
this.rootCommand = rootCommand;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void lastSeen(CommandIssuer issuer, String[] args) {
|
||||
this.rootCommand.lastSeen(issuer,args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.legacy;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.AdventureBaseCommand;
|
||||
|
||||
@CommandAlias("pproxy")
|
||||
@CommandPermission("redisbungee.command.pproxy")
|
||||
public class CommandPProxy extends AdventureBaseCommand {
|
||||
private final LegacyRedisBungeeCommands rootCommand;
|
||||
|
||||
public CommandPProxy(LegacyRedisBungeeCommands rootCommand) {
|
||||
this.rootCommand = rootCommand;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void playerProxy(CommandIssuer issuer, String[] args) {
|
||||
this.rootCommand.playerProxy(issuer,args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.legacy;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.utils.AdventureBaseCommand;
|
||||
|
||||
@CommandAlias("plist|rplist")
|
||||
@CommandPermission("redisbungee.command.plist")
|
||||
public class CommandPlist extends AdventureBaseCommand {
|
||||
|
||||
|
||||
private final LegacyRedisBungeeCommands rootCommand;
|
||||
|
||||
public CommandPlist(LegacyRedisBungeeCommands rootCommand) {
|
||||
this.rootCommand = rootCommand;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void playerList(CommandIssuer issuer, String[] args) {
|
||||
this.rootCommand.playerList(issuer, args);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user