Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.
/ JBridge Public archive

JBridge facilitates communication in minecraft bedrock networks, between Nukkit servers and WaterdogPE proxies using Redis

License

Notifications You must be signed in to change notification settings

JossArchived/JBridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JBridge facilitates communication in minecraft bedrock networks, between Nukkit servers and WaterdogPE proxies using Redis

Features πŸ“ƒ

  • Server management system available for both clients

    Example: This code is used in the same way for jbridge-lobby-nukkit and jbridge-lobby-waterdogpe.

as the first parameter a list with the group of services for the lobby and as the second parameter the sort mode, in this case LOWEST, the algorithm will choose the lobby server with the lowest number of players to balance the lobby servers

  • Packet system using message broker

We have a packet system in which you can create your own packets and manage them in a simple way, of course if you are a developer, as an additional note you can create async packets, especially for tasks that can cause lag, when a packet arrives at a service, it will execute the async by calling the method "onReceive(DataPacket packet);" of your PacketHandler

As an example to use jbridge, we have a lobby balancing system, compatible with nukkit and waterdogpe, from nukkit you will have the /hub command available, From waterdogpe you will have a Custom JoinHandler (which will look for a balanced server in the lobby service list and send the player) and a Custom ReconnectHandler (which will be used when the player is disconnected from an old service for some reason, and will be sent to a balanced lobby).

  • Custom commands to manage servers/services

By WaterdogPE we have the commands:

  • /wdlist: command waterdgope, overwritten for more compatibility with JBridge, will show the list of servers, with their ids, players, group, region and branch (PERMISSION: waterdog.command.list.permission, ALIASES: "servicelist", "services", "servers", "glist", "rglist")
  • /whereami: Provide information about the proxy you are on (ALIASES: "connection")

By Nukkit we have the commands:

  • /transfer: It will send you to the server that you write, you can write the first two letters of the server and it will autocomplete (PERMISSION: jbrdige.command.transfer)

  • /whereami: Provide information about the server you are on (ALIASES: "connection")

  • Custom Query and Ping events

Each time a new service is added, the new available slots are added

  • Server Cluster System

As I mentioned before, jbridge can manage services by groups, you can see more about it here

  • Automatic server registration at WaterdogPE without the need to specify servers manually in the Waterdog config.

  • Multi-group support

Download and setup πŸ›’

Java CI with Maven

Nukkit
  1. Download the latest jbridge-nukkit.jar here
  2. Place the .jar in the plugins/ folder of your server
  3. Start your server
  4. Configure the service and your redis client in plugins/JBridge/config.yml
Waterdog
  1. Download the latest jbridge-waterdogpe.jar here
  2. Place the .jar in the plugins/ folder of your server
  3. Start your server
  4. Configure the service and your redis client in plugins/JBridge/config.yml
How to configure
debug: true #Just for development, to show the internal process of JBridge commons
#recommendation to set this to false to avoid saturating the console with logs

redis: #the configuration of your redis
  hostname: "localhost"
  port: 6379
  password: "yourpasswordhere"

service: #configuration of your service
  id: "hub-1" #the id of your service, if you remove this section, the system will generate a custom id each time the plugin is enabled
  group: "hub" #the group your service belongs to
  region: "us" #the region to which your service belongs
  branch: "dev" #the branch of your service, if it is "dev" the address will automatically change to "127.0.0.1"
  address: "0.0.0.0" #the address of your service, if you remove this section you will get the address that is in server.propierties

For developers πŸ§‘β€πŸ’»

Add JBridge to your project

Common

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.github.Josscoder.JBridge</groupId>
        <artifactId>jbridge-common</artifactId>
        <version>TAG</version>
    </dependency>
</dependencies>

Nukkit

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.github.Josscoder.JBridge</groupId>
        <artifactId>jbridge-nukkit</artifactId>
        <version>TAG</version>
    </dependency>
</dependencies>

WaterdogPE

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.github.Josscoder.JBridge</groupId>
        <artifactId>jbridge-waterdogpe</artifactId>
        <version>TAG</version>
    </dependency>
</dependencies>

Code examples

Register packets
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import me.josscoder.jbridge.JBridgeCore;
import me.josscoder.jbridge.packet.DataPacket;
import me.josscoder.jbridge.packet.PacketManager;

public class Test {
    
    static class HelloWorldPacket extends DataPacket {
        
        public String message;

        public HelloWorldPacket() {
            super((byte) 0x53);
        }

        @Override
        public void encode(ByteArrayDataOutput output) {
            output.writeUTF(message);
        }

        @Override
        public void decode(ByteArrayDataInput input) {
            message = input.readUTF();
        }
    }

    public static void main(String[] args) {
        PacketManager packetManager = JBridgeCore.getInstance().getPacketManager();
        
        packetManager.subscribePacket(new HelloWorldPacket());
    }
}
Register PacketHandlers
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import me.josscoder.jbridge.JBridgeCore;
import me.josscoder.jbridge.packet.DataPacket;
import me.josscoder.jbridge.packet.PacketHandler;
import me.josscoder.jbridge.packet.PacketManager;

public class Test {

  static class HelloWorldPacket extends DataPacket {

    public String message;

    public HelloWorldPacket() {
      super((byte) 0x53);
    }

    @Override
    public void encode(ByteArrayDataOutput output) {
      output.writeUTF(message);
    }

    @Override
    public void decode(ByteArrayDataInput input) {
      message = input.readUTF();
    }
  }

  public static void main(String[] args) {
    PacketManager packetManager = JBridgeCore.getInstance().getPacketManager();

    packetManager.subscribePacket(new HelloWorldPacket());

    packetManager.addPacketHandler(new PacketHandler() {
      @Override
      public void onSend(DataPacket packet) {
        if (packet instanceof HelloWorldPacket) {
          System.out.println("Sending hello world message!!");
        }
      }

      @Override
      public void onReceive(DataPacket packet) {
        if (packet instanceof HelloWorldPacket) {
          System.out.println(((HelloWorldPacket) packet).message);
        }
      }
    });
  }
}
Using AsyncPacket
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import me.josscoder.jbridge.JBridgeCore;
import me.josscoder.jbridge.packet.AsyncPacket;
import me.josscoder.jbridge.packet.DataPacket;
import me.josscoder.jbridge.packet.PacketHandler;
import me.josscoder.jbridge.packet.PacketManager;

public class Test {
    
    static class HelloWorldPacket extends DataPacket implements AsyncPacket {
        
        public String message;

        public HelloWorldPacket() {
            super((byte) 0x53);
        }

        @Override
        public void encode(ByteArrayDataOutput output) {
            output.writeUTF(message);
        }

        @Override
        public void decode(ByteArrayDataInput input) {
            message = input.readUTF();
        }
    }

    public static void main(String[] args) {
        PacketManager packetManager = JBridgeCore.getInstance().getPacketManager();
        
        packetManager.subscribePacket(new HelloWorldPacket());
        
        packetManager.addPacketHandler(new PacketHandler() {
            @Override
            public void onSend(DataPacket packet) {
                if (packet instanceof HelloWorldPacket) {
                    System.out.println("Sending hello world message!!");
                }
            }

            @Override
            public void onReceive(DataPacket packet) {
                if (packet instanceof HelloWorldPacket) {
                    System.out.println("HI!! receiving async packet " + ((HelloWorldPacket) packet).message);
                }
            }
        });
    }
}

Included libraries πŸ› οΈ

Credits πŸ™‹β€β™‚οΈπŸ™‹β€β™€οΈ

License 🚩

JBridge is licensed under the permissive Apache License 2.0 LICENSE. Please see LICENSE for more information.