-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update cloudnet dependency and did some improvements to some c…
…ommands + changed the way how the global playercount works
- Loading branch information
Showing
9 changed files
with
129 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/de/bypixeltv/redivelocity/managers/RedisManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.bypixeltv.redivelocity.managers; | ||
|
||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.JedisPool; | ||
import redis.clients.jedis.JedisPubSub; | ||
|
||
import java.util.List; | ||
|
||
public class RedisManager { | ||
|
||
private final JedisPool jedisPool; | ||
|
||
public RedisManager(JedisPool jedisPool) { | ||
this.jedisPool = jedisPool; | ||
} | ||
|
||
public void subscribe(List<String> channels, RedisMessageListener onMessage) { | ||
JedisPubSub jedisPubSub = new JedisPubSub() { | ||
@Override | ||
public void onPMessage(String pattern, String channel, String message) { | ||
onMessage.onMessage(pattern, channel, message); | ||
} | ||
}; | ||
|
||
new Thread(() -> { | ||
try (Jedis jedis = jedisPool.getResource()) { | ||
jedis.psubscribe(jedisPubSub, channels.toArray(new String[0])); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
}).start(); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface RedisMessageListener { | ||
void onMessage(String pattern, String channel, String message); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/de/bypixeltv/redivelocity/pubsub/MessageListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package de.bypixeltv.redivelocity.pubsub; | ||
|
||
import com.velocitypowered.api.proxy.ProxyServer; | ||
import de.bypixeltv.redivelocity.managers.RedisManager; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import org.json.JSONObject; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Singleton | ||
public class MessageListener { | ||
|
||
private static final List<String> channels = List.of("redivelocity-kick"); | ||
|
||
private final RedisManager redisManager; | ||
private final ProxyServer proxyServer; | ||
|
||
@Inject | ||
public MessageListener(RedisManager redisManager, ProxyServer proxyServer) { | ||
this.redisManager = redisManager; | ||
this.proxyServer = proxyServer; | ||
init(); | ||
} | ||
|
||
private void init() { | ||
redisManager.subscribe(channels, (pattern, channel, msg) -> { | ||
if ("redivelocity-kick".equals(channel)) { | ||
JSONObject message = new JSONObject(msg); | ||
String messagesString = message.getString("messages"); | ||
JSONObject data = new JSONObject(messagesString); | ||
if (data.has("uuid") && data.has("reason")) { | ||
UUID uuid = UUID.fromString(data.getString("uuid")); | ||
String reason = data.getString("reason"); | ||
|
||
proxyServer.getPlayer(uuid).ifPresent(player -> player.disconnect(MiniMessage.miniMessage().deserialize(reason))); | ||
} | ||
} | ||
}); | ||
} | ||
} |