Question Redirect player to another server from Paper plugin

meexreay

New member
Aug 17, 2023
1
0
1
Here's how I have everything set up:

Code:
velocity:
  server_1: (paper)
    paper_plugin.jar
  velocity_2:
    server_2 (spigot)

And I want to redirect the player from server_1 to velocity_2 when the player presses the sign


How do I register plugin messaging:

Java:
public void onEnable() {
    me = this;

    getPluginManager().registerEvents(this,this);

    getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
}
    
public void onDisable() {
    getMessenger().unregisterOutgoingPluginChannel(this,"BungeeCord");
    getMessenger().unregisterIncomingPluginChannel(this,"BungeeCord");
}

@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
    if (!channel.equals("BungeeCord")) return;
    ByteArrayDataInput in = ByteStreams.newDataInput(message);
    System.out.println(player.getName()+" "+in.readUTF());
}

How do I try to connect player to another server:

Java:
public static void connectServer(Player p,String server) {
    p.sendMessage("connecting to server "+server+" ...");
    try {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF(server);
        p.sendPluginMessage(MainPlugin.me,"BungeeCord",out.toByteArray());
    } catch (Exception e) {
        p.sendMessage("error when connecting to "+server+": "+e.getMessage());
    }
}

Now everything that I sent works so I click on the sign, a message is sent about the start of the connection, but I am not redirected
Please help me I can't figure out what I'm doing wrong
 
Version Output
Velocity 3.2.0-SNAPSHOT (git-bda1430d-b259)

Falkys

New member
Feb 28, 2024
1
0
1
Here's how I have everything set up:

Code:
velocity:
  server_1: (paper)
    paper_plugin.jar
  velocity_2:
    server_2 (spigot)

And I want to redirect the player from server_1 to velocity_2 when the player presses the sign


How do I register plugin messaging:

Java:
public void onEnable() {
    me = this;

    getPluginManager().registerEvents(this,this);

    getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
}
   
public void onDisable() {
    getMessenger().unregisterOutgoingPluginChannel(this,"BungeeCord");
    getMessenger().unregisterIncomingPluginChannel(this,"BungeeCord");
}

@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
    if (!channel.equals("BungeeCord")) return;
    ByteArrayDataInput in = ByteStreams.newDataInput(message);
    System.out.println(player.getName()+" "+in.readUTF());
}

How do I try to connect player to another server:

Java:
public static void connectServer(Player p,String server) {
    p.sendMessage("connecting to server "+server+" ...");
    try {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF(server);
        p.sendPluginMessage(MainPlugin.me,"BungeeCord",out.toByteArray());
    } catch (Exception e) {
        p.sendMessage("error when connecting to "+server+": "+e.getMessage());
    }
}

Now everything that I sent works so I click on the sign, a message is sent about the start of the connection, but I am not redirected
Please help me I can't figure out what I'm doing wrong
did you find how to do it?