1. Welcome to LilyPad. Download the project, explore the forums, and create your own LilyPad network.


    If you use the software and enjoy it or have a question, or would like to contribute to the future of the software directly or through resources, please sign up and join our little community.

Help! MessageListeners aren't receiving any messages

Discussion in 'Support' started by Gecko, May 2, 2015.

  1. Gecko

    Gecko New Member

    Hey all,

    I'm trying to set up a basic GoLilyPad network and send messages between 2 servers but I'm having trouble.

    I've set up the Connect and the Proxy, and all works fine. I can hop between the 2 servers using the /server command.
    But I'm trying to send requests to each server back and forth but the MessageListeners aren't receiving anything.

    Here is where I initialize the Connect in my onEnable()

    Code (text):

        @Override
        public void onEnable() {
           
            manager = new GameManager(this);
            dbManager = new DatabaseManager(this);
            listener = new PlayerListener(this, manager);
            msgListener = new MessageListener(this);
            getServer().getPluginManager().registerEvents(listener, this);

            connect = (Connect) getServer().getServicesManager().getRegistration(Connect.class).getProvider(); //Initialize Lilypad Connect
            connect.registerEvents(msgListener); //Register the MessageListener to LilyPad
           
           
            loadConfig();
            loadDatabase();
            loadServerInfo();
            loadSpawns();
           
            LOG.info(LOG_PREFIX + " v" + this.getDescription().getVersion() + " Enabled.");

        }

    Here is where I send requests

    Code (text):

        public Connect getBukkitConnect() {

            return (Connect) plugin.getServer().getServicesManager().getRegistration(Connect.class).getProvider();

        }

        protected void requestAll(String channel, String message) {

            try {
                MessageRequest request = new MessageRequest(new ArrayList(), channel, message);
                System.out.println("Sending request to all");
                plugin.connect.request(request);
            } catch (UnsupportedEncodingException | RequestException e) {
                e.printStackTrace();
            }

        }

    And finally my listener

    Code (text):
    import java.io.UnsupportedEncodingException;
    import lilypad.client.connect.api.MessageEvent;
    import lilypad.client.connect.api.event.EventListener;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;

    public class MessageListener implements Listener {

        private final MyPlugin plugin;
       
        public MessageListener(final MyPlugin plugin) {
           
            this.plugin = plugin;
           
        }
       
        @EventListener
        public void onMessage(MessageEvent me) {
           
            System.out.println("Message received.");
           
            if (!me.getChannel().equals("ch")) {  //name of channel
                return;
            }
           
            String sender = me.getSender(); //gets the server it was sent from
            String message = "Error";
            try {
               
                message = me.getMessageAsString(); //set string message to the message sent
                System.out.println("Message Received: " + sender + " sent the message: " + message);
               
                String returnMsg = message;
                for(Player p : plugin.getServer().getOnlinePlayers()) {
                   
                    returnMsg += p.getName() + " ";
                   
                }
               
                returnMsg = returnMsg.trim();
               
                plugin.networker.request(sender, returnMsg);
               
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
       
    }
     


    Please help me, I have been at this bug for 3 days straight now. The "Message received." print doesn't even trigger inside onMessage(), I have no idea what to do.
  2. Superfuzzy

    Superfuzzy Member

    Did it work before these three days?
    Or do know if this bug is only within your plugin or if no plugin with messages works?

    If the bug is in your plugin, try "Collections.emptyList();" instead of "new ArrayList" in your request (might not work either but its worth a try since new ArrayList creates an empty array that must not be with the size 0..)

    Also you don't need MessageListener implement Listener (that's only for the Bukkit Listener)

    I hope you'll get it fixed
    - superfuzzy

Share This Page