-1

I encountered this problem, sending from a Paper Server a message (containing the command to be executed as String) through this code:

ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(executor.getExecutable().replace("%player%",player.getName()));
System.out.println(executor.getExecutable().replace("%player%", player.getName()));
player.sendPluginMessage(plugin, "hqueue:inventory", out.toByteArray());

(executor.getExecutable() returns a Command as String)

Bungeecord receives these value when made a Println through this code:

    @EventHandler
    public void onPluginMessageReceived(PluginMessageEvent event) {
        System.out.println("Data received: " + new String(event.getData()) + " --r");
        if(!event.getTag().equals("hqueue:inventory")) return;
        System.out.println("Data received: " + new String(event.getData()));
        ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), new String(event.getData()));
    
    
    }

Println results:

11:04:29 [INFO] Data received:  §queue add Jaamin test --r
11:04:29 [INFO] Data received:  §queue add Jaamin test

(§ with some extras spaces shouldn't be there)

And rightly, the command is not executed as it does not exist in that form.

1 Answers1

-1

Fixed using this code to read:

if(!event.getTag().equals("hqueue:inventory")) return;
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(event.getData()));
String command = "";
try {
    command = dataInputStream.readUTF();
} catch (IOException e) {
    e.printStackTrace();
}
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command);

And this one to write:

                ByteArrayOutputStream b = new ByteArrayOutputStream();
                DataOutputStream out = new DataOutputStream(b);
                try {
                    out.writeUTF(executor.getExecutable().replace("%player%", player.getName()));
                } catch(Exception e) {
                    e.printStackTrace();
                }

                player.sendPluginMessage(plugin, "hqueue:inventory", b.toByteArray());