[Solved] /server <server name> command won't work on plugin

Discussion in 'Spigot Plugin Development' started by RandomPanda30, May 12, 2015.

  1. So I'm currently working on a plugin and I've decided to use commands to move players from servers (This is configurable don't worry) and I have this code.

    Code (Text):
    if (collection.isUseCommand()) {
                player.performCommand("server " + collection.getLobby());
    But it just says "Unknown command" on the server. Any ideas why?
     
  2. You will need to use the Bungee messaging channel.
     
  3. Ohhhh dear and erm, any tutorials or anything as to how to implement this? .-.
     
  4. Oh wait nevermind found it. Problem is, why won't this command just work as is? The command works normally when in game and all I'm doing is just performing it in the code? Rather confused at this point xD
     
  5. It's a bungee command, so it's never registered on Spigot.
     
  6. In your on Enable open the channel.
    Code (Text):
    Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    Send the player
    Code (Text):
        public static void sendPlayerToServer(Player player, String server){
            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF("Connect");
            out.writeUTF(server);
            player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
        }
     
    • Like Like x 3
  7. Ah that simple? Alright well thank you. I'll work on using the messaging channel then. Thank you.
     
  8. That simple? Well alright, thank you for this as well. Gives a good starting point
     
  9. It might also be worth it to check the wiki page on plugin messaging
     
  10. Yeah this is currently my main source of doing this. Haven't worked with this before, it's quite fun ^-^
     
  11. The Plugin Messaging Channel only works if there is at least one player online on the target server. I personally use Sockets because they can transfer data even with no players online.
     
  12. Which one should be used depends on the use case, really. For half the messages, it wouldn't make any sense to use it without actual players online.

    If you still require sockets, make sure you make them secure ;).
     
  13. Hmmm I'll take this into account for the future. For now, since I'm working with players anyway, I'll just do that for now. Thanks for the help!
     
  14. What does a socket make safe according to you?
     
  15. Blocking requests which are from an IP which is not whitelisted, and giving them a random token which they need in a subsequent request to prevent IP spoofing.