Discussion in 'Spigot Plugin Development' started by Limesix, May 28, 2017.

  1. Hey guys,

    i'm making a Hub-plugin, but can't find out how to connect to other bungeecord-servers by a command - this is my code, but it doesn't work:

    Code (Text):
    package me.limesix.hub.cmds;

    import com.google.common.io.ByteArrayDataOutput;
    import com.google.common.io.ByteStreams;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.ChatColor;
    import org.bukkit.plugin.Plugin;

    public class AtlantisCMD implements CommandExecutor {

        public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
            if (cmd.getName().equalsIgnoreCase("Atlantis")) {
                Player player = (Player) sender;
                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                player.sendPluginMessage((Plugin) this, "BungeeCord", out.toByteArray());
                player.sendMessage(ChatColor.GREEN + "Connecting...");
            } return true;

    Btw, "Atlantis" is the name of the server.

    Thank you very much for your help in advance,

  2. Ingame: /server [server]
    In Plugin: player.connect

    or do you mean otherwise ?
  3. ScarabCoder

    ScarabCoder Retired Resource Staff

    Doesn't work, as in it throws an error? Or does the command get executed properly, but it doesn't send the player to the server?
    If the former, make sure you've registered BungeeCord as a messaging channel in onEnable().
    • Agree Agree x 1
  4. Mas


    Make sure you've registered the outgoing plugin channel. Bukkit.getMessenger().registerOutgoing() or something like that.
  5. How do i register the outgoing plugin channel? (I'm still new to java, so please bare with my stupid questions).
  6. In your "onEnable" write this:

    Code (Text):
            Bukkit.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new ClassThatImplementsPluginMessageListener());
            Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    Here is my PluginMessageListener class if you want an example.
  7. Mas


    Check the command sender is a Player before casting (sender instanceof Player)

    No need to register incoming channels if he isn't listening to any.

  8. Code (Text):
    if (cmd.getName().equalsIgnoreCase("Atlantis") &&sender instanceof Player) {

    Changed the command to this, however - should i register the channels or not? :)
  9. 3 users have said you should.
  10. Why oh why are you trying to use the class instance in your #sendPluginMessage and cast it as a Plugin. Just pass the main instance...