onPluginMessageReceived not working when sending from velocity to spigot

I’m learning how velocity plugins work for my minecraft network, and I wanted to make a simple /screenshare (player) command to bring both players onto the screenshare server. Since i want the spigot plugin (that only goes on the screenshare server) to know which player is the staffer and which is the suspect, I found out about plugin messaging channel. I kinda understood how it works, when I send a message from spigot to velocity, the velocity servers gets it and prints it, but when sending from the velocity to spigot it won’t.

I know that velocity will only message spigot if there’s at least one player online, i even had the plugin to wait 2seconds before running the code, but still nothing. This is the code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
@Override
public void onEnable() {
getServer().getMessenger().registerOutgoingPluginChannel(this, "test:screenshare");
getServer().getMessenger().registerIncomingPluginChannel(this, "test:screenshare", this);
// Registra l'evento PlayerJoin
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (!(channel.equals("test:screenshare"))) {
getLogger().info("Wrong channel: " + channel);
return;
}
new BukkitRunnable() {
@Override
public void run() {
ByteArrayDataInput in = ByteStreams.newDataInput(message);
String subchannel = in.readUTF();
if (subchannel.equals("RoleUpdate")) {
String stafferRole = in.readUTF();
String stafferName = in.readUTF();
String suspectRole = in.readUTF();
String suspectName = in.readUTF();
getLogger().info("Received roles: " + stafferRole + " for " + stafferName + " and " + suspectRole + " for " + suspectName);
} else {
getLogger().info("Subchannel not found: " + subchannel);
}
}
}.runTaskLater(this, 40L);
}
</code>
<code> @Override public void onEnable() { getServer().getMessenger().registerOutgoingPluginChannel(this, "test:screenshare"); getServer().getMessenger().registerIncomingPluginChannel(this, "test:screenshare", this); // Registra l'evento PlayerJoin getServer().getPluginManager().registerEvents(this, this); } @Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { if (!(channel.equals("test:screenshare"))) { getLogger().info("Wrong channel: " + channel); return; } new BukkitRunnable() { @Override public void run() { ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals("RoleUpdate")) { String stafferRole = in.readUTF(); String stafferName = in.readUTF(); String suspectRole = in.readUTF(); String suspectName = in.readUTF(); getLogger().info("Received roles: " + stafferRole + " for " + stafferName + " and " + suspectRole + " for " + suspectName); } else { getLogger().info("Subchannel not found: " + subchannel); } } }.runTaskLater(this, 40L); } </code>

    @Override
    public void onEnable() {
        getServer().getMessenger().registerOutgoingPluginChannel(this, "test:screenshare");
        getServer().getMessenger().registerIncomingPluginChannel(this, "test:screenshare", this);

        // Registra l'evento PlayerJoin
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onPluginMessageReceived(String channel, Player player, byte[] message) {
        if (!(channel.equals("test:screenshare"))) {
            getLogger().info("Wrong channel: " + channel);
            return;
        }

        new BukkitRunnable() {
            @Override
            public void run() {
                ByteArrayDataInput in = ByteStreams.newDataInput(message);
                String subchannel = in.readUTF();

                if (subchannel.equals("RoleUpdate")) {
                    String stafferRole = in.readUTF();
                    String stafferName = in.readUTF();
                    String suspectRole = in.readUTF();
                    String suspectName = in.readUTF();

                    getLogger().info("Received roles: " + stafferRole + " for " + stafferName + " and " + suspectRole + " for " + suspectName);
                } else {
                    getLogger().info("Subchannel not found: " + subchannel);
                }
            }
        }.runTaskLater(this, 40L);
    }

and this is the velocity part of the code:

public static final MinecraftChannelIdentifier IDENTIFIER = MinecraftChannelIdentifier.from("test:screenshare");

sendPluginMessage(staffer.getUsername(), suspect.getUsername(), "Staffer", "Suspect"); function called upon running the /ss command on velocity.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> private void sendPluginMessage(String stafferName, String suspectName, String stafferRole, String suspectRole) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("RoleUpdate");
out.writeUTF(stafferRole);
out.writeUTF(stafferName);
out.writeUTF(suspectRole);
out.writeUTF(suspectName);
Optional<Player> anyConnectedPlayer = proxy.getAllPlayers().stream().findAny();
if (anyConnectedPlayer.isPresent()) {
Optional<ServerConnection> connection = anyConnectedPlayer.get().getCurrentServer();
if (connection.isPresent()) {
connection.get().sendPluginMessage(IDENTIFIER, out.toByteArray());
logger.info("Message sent to spigot, staffer name: " + stafferName + " (role: " + stafferRole + ") and suspect: " + suspectName + " (role: " + suspectRole + ")");
} else {
logger.warn("No connection was found for player: " + anyConnectedPlayer.get().getUsername());
}
} else {
logger.warn("No players connected to send message to the spigot server.");
}
}
</code>
<code> private void sendPluginMessage(String stafferName, String suspectName, String stafferRole, String suspectRole) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("RoleUpdate"); out.writeUTF(stafferRole); out.writeUTF(stafferName); out.writeUTF(suspectRole); out.writeUTF(suspectName); Optional<Player> anyConnectedPlayer = proxy.getAllPlayers().stream().findAny(); if (anyConnectedPlayer.isPresent()) { Optional<ServerConnection> connection = anyConnectedPlayer.get().getCurrentServer(); if (connection.isPresent()) { connection.get().sendPluginMessage(IDENTIFIER, out.toByteArray()); logger.info("Message sent to spigot, staffer name: " + stafferName + " (role: " + stafferRole + ") and suspect: " + suspectName + " (role: " + suspectRole + ")"); } else { logger.warn("No connection was found for player: " + anyConnectedPlayer.get().getUsername()); } } else { logger.warn("No players connected to send message to the spigot server."); } } </code>
    private void sendPluginMessage(String stafferName, String suspectName, String stafferRole, String suspectRole) {
            ByteArrayDataOutput out = ByteStreams.newDataOutput();

            out.writeUTF("RoleUpdate");
            out.writeUTF(stafferRole);
            out.writeUTF(stafferName);
            out.writeUTF(suspectRole);
            out.writeUTF(suspectName);

            Optional<Player> anyConnectedPlayer = proxy.getAllPlayers().stream().findAny();
            if (anyConnectedPlayer.isPresent()) {
                Optional<ServerConnection> connection = anyConnectedPlayer.get().getCurrentServer();
                if (connection.isPresent()) {
                    connection.get().sendPluginMessage(IDENTIFIER, out.toByteArray());
                    logger.info("Message sent to spigot, staffer name: " + stafferName + " (role: " + stafferRole + ") and suspect: " + suspectName + " (role: " + suspectRole + ")");
                } else {
                    logger.warn("No connection was found for player: " + anyConnectedPlayer.get().getUsername());
                }
            } else {
                logger.warn("No players connected to send message to the spigot server.");
            }
        }

the logger “”Message sent to spigot, staffer name: ” + stafferName + ” (role: ” + stafferRole + “) and suspect: ” + suspectName + ” (role: ” + suspectRole + “)”)” shows up in console and everything’s fine, but spigot won’t say anything.
What am I missing?

Tried using bungee’s channel instead of custom one, tried adding more time before having the spigot’s server to receive the message from velocity, searched online but beside these 2 issues I didn’t found anyone else having the same problem.

It’s like velocity can read messages sent from my spigot server, but my spigot server can’t read messages from velocity.

You are trying to send a message to the player, and intercept it by the spigot, which could not work.

To explain, here is how it works:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Spigot <=> Velocity <=> Player
</code>
<code>Spigot <=> Velocity <=> Player </code>
Spigot    <=>   Velocity   <=>   Player

Spigot sendPluginMessage(), it will do: spigot -> velocity -> player. Actually, you intercept it on Velocity (I suggest you to cancel it).

Your Velocity code is trying to do: velocity -> player. Which will not works. It should do the opposite: spigot <- velocity (send to “child”, as spigot is below Velocity)

You have to get the server where you want to send the information, then use sendPluginMessage from the server object, to send it to the server itself.

Example code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>private void sendPluginMessage(String stafferName, String suspectName, String stafferRole, String suspectRole) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("RoleUpdate");
out.writeUTF(stafferRole);
out.writeUTF(stafferName);
out.writeUTF(suspectRole);
out.writeUTF(suspectName);
byte[] data = out.toByteArray();
for(RegisteredServer server : proxy.getAllServers()) {
server.sendPluginMessage(IDENTIFIER, data);
logger.info("Message sent to server " + server.getServerInfo().getName() + ", staffer name: " + stafferName + " (role: " + stafferRole + ") and suspect: " + suspectName + " (role: " + suspectRole + ")");
}
}
</code>
<code>private void sendPluginMessage(String stafferName, String suspectName, String stafferRole, String suspectRole) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("RoleUpdate"); out.writeUTF(stafferRole); out.writeUTF(stafferName); out.writeUTF(suspectRole); out.writeUTF(suspectName); byte[] data = out.toByteArray(); for(RegisteredServer server : proxy.getAllServers()) { server.sendPluginMessage(IDENTIFIER, data); logger.info("Message sent to server " + server.getServerInfo().getName() + ", staffer name: " + stafferName + " (role: " + stafferRole + ") and suspect: " + suspectName + " (role: " + suspectRole + ")"); } } </code>
private void sendPluginMessage(String stafferName, String suspectName, String stafferRole, String suspectRole) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();

    out.writeUTF("RoleUpdate");
    out.writeUTF(stafferRole);
    out.writeUTF(stafferName);
    out.writeUTF(suspectRole);
    out.writeUTF(suspectName);
    byte[] data = out.toByteArray();

    for(RegisteredServer server : proxy.getAllServers()) {
        server.sendPluginMessage(IDENTIFIER, data);
        logger.info("Message sent to server " + server.getServerInfo().getName() + ", staffer name: " + stafferName + " (role: " + stafferRole + ") and suspect: " + suspectName + " (role: " + suspectRole + ")");
    }
}

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật