Skip to content

Commit c3980ce

Browse files
Add support for Velocity's RedisBungee (ValioBungee)
1 parent 424a1b7 commit c3980ce

5 files changed

Lines changed: 78 additions & 6 deletions

File tree

WarpSystem/WarpSystem-Proxy/WarpSystem-Proxy-BungeeCord/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<dependency>
7171
<groupId>com.imaginarycode.minecraft</groupId>
7272
<artifactId>RedisBungee</artifactId>
73+
<version>0.3.8-SNAPSHOT</version>
7374
<scope>provided</scope>
7475
</dependency>
7576
</dependencies>

WarpSystem/WarpSystem-Proxy/WarpSystem-Proxy-Velocity/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,12 @@
6666
<version>3.1.1</version>
6767
<scope>provided</scope>
6868
</dependency>
69+
<dependency>
70+
<groupId>com.github.ProxioDev.ValioBungee</groupId>
71+
<artifactId>RedisBungee-Velocity</artifactId>
72+
<version>0.12.6</version>
73+
<scope>provided</scope>
74+
</dependency>
6975
</dependencies>
76+
7077
</project>

WarpSystem/WarpSystem-Proxy/WarpSystem-Proxy-Velocity/src/main/java/de/codingair/warpsystem/velocity/base/WarpSystem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import de.codingair.warpsystem.velocity.base.listeners.MainListener;
2323
import de.codingair.warpsystem.velocity.base.listeners.SetupAssistantListener;
2424
import de.codingair.warpsystem.velocity.base.managers.*;
25+
import de.codingair.warpsystem.velocity.redis.RedisBungeeHandler;
2526
import de.codingair.warpsystem.velocity.utils.VelocityHandler;
2627
import de.codingair.warpsystem.velocity.utils.VelocityPlayer;
2728
import de.codingair.warpsystem.velocity.utils.VelocityScheduleTask;
@@ -159,7 +160,13 @@ private void checkRedis() {
159160
if (!enabled) {
160161
name = "Disabled";
161162
} else if (proxy.getPluginManager().getPlugin("trevor").isPresent()) {
163+
name = "Trevor";
162164
RedisCore.core().setHandler(new TrevorHandler());
165+
} else if (proxy.getPluginManager().getPlugin("redisbungee").isPresent()) {
166+
name = "RedisBungee";
167+
RedisBungeeHandler handler = new RedisBungeeHandler();
168+
proxy.getEventManager().register(this, handler);
169+
RedisCore.core().setHandler(handler);
163170
}
164171

165172
log("Redis hook: " + name);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package de.codingair.warpsystem.velocity.redis;
2+
3+
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
4+
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
5+
import com.velocitypowered.api.event.Subscribe;
6+
import de.codingair.warpsystem.core.proxy.redis.RedisHandler;
7+
import de.codingair.warpsystem.core.proxy.transfer.CoreDataHandler;
8+
9+
import java.io.*;
10+
import java.util.Base64;
11+
12+
public class RedisBungeeHandler extends RedisHandler {
13+
public RedisBungeeHandler() {
14+
super(RedisBungeeAPI.getRedisBungeeApi().getProxyId(), CoreDataHandler.redisChannel);
15+
}
16+
17+
@Override
18+
public void send(byte[] data) {
19+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
20+
DataOutputStream out = new DataOutputStream(stream);
21+
22+
try {
23+
out.writeUTF(source);
24+
25+
//use Base64 to avoid virtual ends for the packet stream
26+
byte[] encoded = Base64.getEncoder().encode(data);
27+
out.writeUTF(new String(encoded));
28+
29+
RedisBungeeAPI.getRedisBungeeApi().sendChannelMessage(channel, stream.toString());
30+
} catch (IOException e) {
31+
e.printStackTrace();
32+
}
33+
}
34+
35+
@Override
36+
public void registerChannel() {
37+
38+
}
39+
40+
@Override
41+
public void unregisterChannel() {
42+
43+
}
44+
45+
@Subscribe
46+
public void onPubSub(PubSubMessageEvent e) {
47+
if (e.getChannel().equals(channel)) {
48+
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getMessage().getBytes()));
49+
50+
try {
51+
String source = in.readUTF();
52+
if (source.equals(this.source)) return;
53+
54+
String encoded = in.readUTF();
55+
byte[] data = Base64.getDecoder().decode(encoded.getBytes());
56+
57+
sink.receive(data, source);
58+
} catch (IOException ex) {
59+
ex.printStackTrace();
60+
}
61+
}
62+
}
63+
}

WarpSystem/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,6 @@
141141
<version>master-d32606d677-1</version>
142142
<scope>provided</scope>
143143
</dependency>
144-
<dependency>
145-
<groupId>com.imaginarycode.minecraft</groupId>
146-
<artifactId>RedisBungee</artifactId>
147-
<version>0.3.8-SNAPSHOT</version>
148-
<scope>provided</scope>
149-
</dependency>
150144
<dependency>
151145
<groupId>org.geysermc.floodgate</groupId>
152146
<artifactId>api</artifactId>

0 commit comments

Comments
 (0)