Execute command from Spigot in BungeeCord

Discussion in 'BungeeCord Plugin Development' started by Wendell6658, May 25, 2019.

  1. I need execute command from Spigot in BungeeCord, but I don't know how to. I use a more function... for example Forward Channel, Message Channel, BungeeCord.getInstance().dispatchCommand, ProxyServer.getInstance().dispatchCommand.

    None of this options not work. By the way BungeeCord[..].dispatchCommand i ProxyServer send error in console.

    I use BungeeCord API in a first time. I was looking for more options, maybe I used a bad api.
     
  2. Code (Java):
    ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), your_command);
    and check if you have register the channel
     
  3. This runs a bungee command, but not spigot
     
  4. oh!
    sorry i'm sorry for my bad english
    Code (Java):
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), your_command);
     
  5. The OP executes the command from bungeecord..
     
  6. put this code in the spigot plugin
    Code (Java):
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(b);
            try {
                out.writeUTF("BungeeCommand");
                out.writeUTF(your_command);
            } catch (IOException e) {
                e.printStackTrace();
            }
    and register the channel in onEnable void.
    Code (Java):
    Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    --------------------------------------------------------------------------------------------------------------------------------
    in the Bungee Plugin
    first register your channel
    after
    make PluginMessageEvent
    Code (Java):
                if(event.getTag().equalsIgnoreCase(the_channel)) {
                    DataInputStream in = new DataInputStream(new ByteArrayInputStream(event.getData()));
                    String c= in.readUTF();
                    if(!c.equals("BungeeCommand")) {
                        return;
                    }
                    String command = in.readUTF();
                    ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command);
                }
    thats it :D.
     
  7. Ehm, you didn't explained it. Here's explanation.
     
    • Agree Agree x 1

Share This Page