Spigot+Bungee Not all Server's Intercept Event

Discussion in 'Spigot Plugin Development' started by Bladian, May 18, 2016.

  1. I'm basically attempting to send a message via a bukkit plugin, and then intercepting it using a bungee cord event, and then sending it to all servers again.

    I've been trying it out and this is what I've got.

    Code (Text):
    package me.bungeemerge.core;

    import net.md_5.bungee.BungeeCord;
    import net.md_5.bungee.api.config.ServerInfo;
    import net.md_5.bungee.api.event.PluginMessageEvent;
    import net.md_5.bungee.api.plugin.Listener;
    import net.md_5.bungee.event.EventHandler;

    import java.io.*;
    import java.util.Map;

    /**
    * Created by BladianYT
    */
    public class ChannelListener implements Listener
    {

        @EventHandler
        public void onPluginMessage(PluginMessageEvent e) {
            System.out.print("Worked");
            if (e.getTag().equalsIgnoreCase("BungeeCord")) {
                DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
                try {
                    String channel = in.readUTF();
                    if(channel.equals("get")){
                        Map<String, ServerInfo> servers = BungeeCord.getInstance().getServers();
                        System.out.print(servers.keySet().size());
                        for (Map.Entry<String, ServerInfo> en : servers.entrySet()) { // Looping through each Server of Bungee.
                            String name = en.getKey();
                            ServerInfo all = BungeeCord.getInstance().getServerInfo(name);
                            sendToBukkit(channel, "Return", all); // "command" is a sub-channel which will be used to determine the message is sent by this plugin.
                            System.out.print("times");
                        }
                        ServerInfo b = BungeeCord.getInstance().getServerInfo("B");
                        ServerInfo lobby = BungeeCord.getInstance().getServerInfo("lobby");

                        sendToBukkit(channel, "Return", b); // "command" is a sub-channel which will be used to determine the message is sent by this plugin.
                        sendToBukkit(channel, "Return", lobby); // "command" is a sub-channel which will be used to determine the message is sent by this plugin.
                        System.out.print("Yay$");
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

            }
        }

        public void sendToBukkit(String channel, String message, ServerInfo server) {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(stream);
            try {
                out.writeUTF(channel);
                out.writeUTF(message);
            } catch (IOException e) {
                e.printStackTrace();
            }
            server.sendData("Return", stream.toByteArray());

        }
    }
     
    Code (Text):
    package me.bladperms.bungee;

    import me.bladperms.core.Core;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.messaging.PluginMessageListener;

    import java.io.*;
    import java.util.HashMap;

    /**
    * Created by BladianYT
    */
    public class EventBungee implements PluginMessageListener
    {

        private static HashMap<Player, Object> obj = new HashMap<>();

        @Override
        public void onPluginMessageReceived(String s, Player player, byte[] bytes)
        {
            Bukkit.broadcastMessage("oh wow k dat shit be working boy");
            Bukkit.broadcastMessage(s);
            if(!s.equals("Return"))
            {
                return;
            }
            Bukkit.broadcastMessage("Yo this working");
            ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
            DataInputStream in = new DataInputStream(stream);
            String input = null;
            try
            {
                input = in.readUTF();
            } catch (IOException e)
            {
                e.printStackTrace();
            }
            obj.put(player, input);
            Bukkit.broadcastMessage("oh wow k dat shit be working boysferjpgjepr");
        }


        public static void sendToBungeeCord(Player p, String channel, String sub){
            Bukkit.broadcastMessage("oh wow k dat shit be working boy");
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(b);
            try {
                out.writeUTF(channel);
                out.writeUTF(sub);
            } catch (IOException e) {
                e.printStackTrace();
            }
            p.sendPluginMessage(Core.getPlugin(Core.class), "BungeeCord", b.toByteArray());
            Bukkit.broadcastMessage("okay this bitch works");
        }
    }
     
    Up to here everything works fine, and I'm not getting any problems. The bukkit plugin sends, and intercepts the message which is working fine.

    The problem is only 1 server intercepts the message which is the lobby I'm on.

    So if I run the command,

    Lobby: Everything goes smoothly (I'm on this server)
    Bungee: Yep everything here too, no problems
    B: Here nothing finds it, it can't intercept the message and doesn't seem to be able to do anything.

    Thanks.