#Getting all servers on a BungeeCord Network
1 messages · Page 1 of 1 (latest)
How do you register and unregister the channel
@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);
}```
Can you spot the mistake yourself?
no
Would presume this
error happens on sending the message
but that is a issue
thanks for pointing that out
Yeah actually idr if they switched the channel for bungee
the error happens on this line: p.sendPluginMessage(LobbySystem.getInstance(), "BungeeCord", byteArrayOutputStream.toByteArray());
org.bukkit.plugin.messaging.StandardMessenger.validateAndCorrectChannel(StandardMessenger.java:503)
Can you send that method through paste?
I’m curious
@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;
}```
Ah try using bungeecord:main instead
alright
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)
alright
now
I am having issues with something else
a general bungeecord issue
it wont connect me to one of my servers
You’re trying to connect from one to another?
Through plugin messaging with the bungeecord channel?
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
How do you connect the player?
pp?
ProxiedPlayer pp = LobbySystem.getInstance().getProxy().getPlayer(e.getPlayer().getUniqueId());
Oh we are in bungeecord now?
yeah, this connects the player to a random lobby, sorry if I didnt specify that first
Send the full code
Including getRandomLobby method
And the snippet where you connect
@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
Wat is the type of lobbies?
public ArrayList<String> lobbies = new ArrayList<>();
Use ServerConnectEvent instead
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
and then use ServerConnectEvent::setTarget