#Getting all servers on a BungeeCord Network

1 messages · Page 1 of 1 (latest)

south sentinel
strange fox
#

How do you register and unregister the channel

south sentinel
#
    @Override
    public void onEnable() {
        instance = this;
        this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
        this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", lobbyGui);
    }

    @Override
    public void onDisable() {
        this.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
        this.getServer().getMessenger().unregisterIncomingPluginChannel(this);
    }```
strange fox
#

Can you spot the mistake yourself?

south sentinel
#

no

strange fox
#

Would presume this

south sentinel
#

error happens on sending the message

#

but that is a issue

#

thanks for pointing that out

strange fox
#

Yeah actually idr if they switched the channel for bungee

south sentinel
#

the error happens on this line: p.sendPluginMessage(LobbySystem.getInstance(), "BungeeCord", byteArrayOutputStream.toByteArray());

strange fox
#

org.bukkit.plugin.messaging.StandardMessenger.validateAndCorrectChannel(StandardMessenger.java:503)

#

Can you send that method through paste?

#

I’m curious

south sentinel
#
@Deprecated
    @NotNull
    public static String validateAndCorrectChannel(@NotNull String channel) {
        if (channel == null) {
            throw new IllegalArgumentException("Channel cannot be null");
        }
        // This will correct registrations / outgoing messages
        // It is not legal to send "BungeeCord" incoming anymore so we are fine there,
        // but we must make sure that none of the API methods repeatedly call validate
        if (channel.equals("BungeeCord")) {
            return "bungeecord:main";
        }
        // And this will correct incoming messages.
        if (channel.equals("bungeecord:main")) {
            return "BungeeCord";
        }
        if (channel.length() > Messenger.MAX_CHANNEL_SIZE) {
            throw new ChannelNameTooLongException(channel);
        }
        if (channel.indexOf(':') == -1) {
            throw new IllegalArgumentException("Channel must contain : separator (attempted to use " + channel + ")");
        }
        if (!channel.toLowerCase(Locale.ROOT).equals(channel)) {
            // TODO: use NamespacedKey validation here
            throw new IllegalArgumentException("Channel must be entirely lowercase (attempted to use " + channel + ")");
        }
        return channel;
    }```
strange fox
#

Ah try using bungeecord:main instead

south sentinel
#

alright

strange fox
#

Also for the record I’d suggest having a constant (public static final String) for the channel

#

So you only have to change it in one place

#

(And no it doesn’t hit performance)

south sentinel
#

alright

#

now

#

I am having issues with something else

#

a general bungeecord issue

#

it wont connect me to one of my servers

strange fox
#

You’re trying to connect from one to another?

#

Through plugin messaging with the bungeecord channel?

south sentinel
#

this is just connecting to the server

#

I cant test that

#

until this

#

so

#

I have it randomly get 1 of like 40 lobbies, and then send you to it on join, well rn, I am getting this error. [19:39:17 INFO]: [riches_exe|/127.0.0.1:57042] <-> ServerConnector [LOBBY2] has connected [19:39:17 INFO]: [riches_exe] disconnected with: Could not connect to a default or fallback server, please try again later: io.netty.channel.AbstractChannel$AnnotatedConnectException [19:39:17 INFO]: [/127.0.0.1:57042|riches_exe] -> UpstreamBridge has disconnected [19:39:17 WARN]: No client connected for pending server! [19:39:17 INFO]: [riches_exe|/127.0.0.1:57042] <-> ServerConnector [LOBBY2] has disconnected

strange fox
#

How do you connect the player?

south sentinel
#

pp.connect(sv);

#

sv = LobbySystem.getInstance().getRandomLobby();

strange fox
#

pp?

south sentinel
#

ProxiedPlayer pp = LobbySystem.getInstance().getProxy().getPlayer(e.getPlayer().getUniqueId());

strange fox
#

Oh we are in bungeecord now?

south sentinel
#

yeah, this connects the player to a random lobby, sorry if I didnt specify that first

strange fox
#

Send the full code

#

Including getRandomLobby method

#

And the snippet where you connect

south sentinel
#
    @EventHandler
    public void onPlayerJoin(PostLoginEvent e) {
        String type = CustomConfigFile.getConfig().getString("config.join-type");
        ProxiedPlayer pp = LobbySystem.getInstance().getProxy().getPlayer(e.getPlayer().getUniqueId());
        ServerInfo sv;
        if (type.equals("RANDOM")) {
            sv = LobbySystem.getInstance().getRandomLobby();
        }
        else {
            sv = LobbySystem.getInstance().getProxy().getServerInfo("LOBBY2");
        }
        System.out.println(ChatColor.AQUA + "[LobbySystem] >> " + ChatColor.GOLD + "New Player Connected. Sending them lobby " + sv.getName());
        pp.connect(sv);
    }```
#
    public ServerInfo getRandomLobby() {
        Random random = new Random();
        if(lobbies.size() <=0){
            return null;
        }else{
            int ran = random.nextInt(lobbies.size());
            return getInstance().getProxy().getServerInfo(lobbies.get(ran));
        }
    }```
#

it did work

#

I dont know what I did

strange fox
#

Wat is the type of lobbies?

south sentinel
#

public ArrayList<String> lobbies = new ArrayList<>();

strange fox
#

Ah okay

#

Wait does it work now?

south sentinel
#

it did work

#

Idk what I did

#

but now it doesnt

strange fox
#

Use ServerConnectEvent instead

south sentinel
#

on the server LOBBY2 this appears in the console: [19:39:17 INFO]: UUID of player riches_exe is 9d8784f3-aec6-36b9-a449-418e6c366321 [19:39:17 INFO]: riches_exe lost connection: Disconnected

strange fox
#

and then use ServerConnectEvent::setTarget

south sentinel
#

alright

#

I got it working

#

but now I may have another issue

#

it might be 2 things

#
  1. messages sent to bungeecord:main are not being received by the server
  2. I am sending a message, and not waiting long enough for the response