Sending player to another server using redis.

Discussion in 'BungeeCord Plugin Development' started by Ham1255i, Jan 9, 2020.

  1. I am trying to use Redis to connect the player to selected server in proxy using (PUB/SUB), than using plugin message
    so I did write the code and it works,

    here is the way I am doing it:

    first player type command /minigame

    then Spigot plugin Publish Message like this "PlayerName,ServerName" without the " of course

    then Bungeecord receive the message and processing data and sends the player to the selected server

    but it this correct way of doing it?

    code in spigot side

    Code (Text):
    public static void connectPlayer(Player player, String server_name){
            jedis.publish("ServerSwitcher", player.getName()+","+ server_name);
    code in bungeecord side

    Code (Text):
    JedisPubSub s = new JedisPubSub() {
                public void onMessage(String channel, String message) {
                    String[] connect = message.split(",");
            j.subscribe(s, "ServerSwitcher");
    Edit1: bungeecord code uses redis Subscribe which is blocking method so it runs on Async thread
    #1 Ham1255i, Jan 9, 2020
    Last edited: Jan 9, 2020
  2. Do you have sources for that statement? I'm genuinely curious.
  3. You should use JSON or any serializer to send data between BungeeCord --> Spigot and Spigot --> BungeeCord.

    You can use these two classes.


    And the usage:

    In spigot:
    Code (Java):
    String json = new RedisMessage(MessageAction.TELEPORT_PLAYER_TO_HUB)
                    .setParam("player", player.getDisplayName())
    jedis.publish("ChannelHere", json);
    In bungeecord:
    Code (Java):
    JedisPubSub s = new JedisPubSub()
                public void onMessage(String channel, String message)
                    RedisMessage redisMessage = new Gson().fromJson(message, RedisMessage.class);
                    switch (redisMessage.getAction())
                        case TELEPORT_PLAYER_TO_HUB:
                            String playerName = redisMessage.getParam("player");

                            // Do actions here

    j.subscribe(s, "Channel");
    I hope that can help you to optimize your communication.

    I've forgot to say that the class RedisMessage and MessageAction should be the same on Bungee plugin and on Spigot plugin. You can do that by creating an other java project and import this one in bungee project and spigot project.
    • Winner Winner x 1
  4. Okay thanks.
    idk but it happens randomly that bungeecord doesnt get the message not sure why
  5. Thanks for classes, i will try use them later