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 with MessageRequest

Discussion in 'Development' started by Stilldabomb, Aug 22, 2013.

Thread Status:
Not open for further replies.
  1. Stilldabomb

    Stilldabomb New Member

    I've been looking around on the forums, and there is no updated tutorials for MessageRequest, so I've decided to just ask if my code is correct or not.

    Sending:
    Code (text):
    public void sendMessage(String server, Player player)
    {
       
        MessageRequest request = null;
        try
        {
               
            request = new MessageRequest(server, "joining", player.getName() + " is joining!");
           
        }
        catch (UnsupportedEncodingException e){}
        FutureResult<MessageResult> futureResult = null;
        try
        {
           
            futureResult = this.getLilyPad().request(request);
           
        }
        catch (Exception e){
            e.printStackTrace();
        }
        try {
            futureResult.await(10000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
    Receiving:
    Code (text):
    this.chatListener = new LilyPadListener();
    this.getLilyPad().registerEvents(this.chatListener);

    public class LilyPadListener
    {
       
        @EventListener
        void onMessage(MessageEvent event)
        {
           
            String channel = event.getChannel();
            String sender = event.getSender();
            String message = "Error";
            try
            {
               
                event.getMessageAsString();
               
            }
            catch(Exception e)
            {
               
                e.printStackTrace();
               
            }
            plugin.getLogger().info("Message received");
            plugin.getLogger().info("Channel: " + channel);
            plugin.getLogger().info("Sender: " + sender);
            plugin.getLogger().info("Message: " + message);
           
        }
       
    }
    I don't get any errors in Eclipse, the message just doesn't send/get received.

    Any help is much appreciated!

    Thanks,
    Stilldabomb!
  2. Coelho

    Coelho Software Engineer Staff Member Administrator Maintainer

    Are you running this plugin on both the sender and recipient?
  3. Stilldabomb

    Stilldabomb New Member

  4. Stilldabomb

    Stilldabomb New Member

    Oh, and I'm running on the latest build, and sending players to a different server works just fine.

    Thanks,
    Stilldabomb!
  5. Stilldabomb

    Stilldabomb New Member

    Anyways, I will use the old MessageRequest/MessageListener for now.

    Thanks for any future help/fixes,
    Stilldabomb!
  6. Coelho

    Coelho Software Engineer Staff Member Administrator Maintainer

    Oh, it was because you used
    Code (text):

        void onMessage(MessageEvent event)
     
    When it should have been:
    Code (text):

        public void onMessage(MessageEvent event)
     
  7. Stilldabomb

    Stilldabomb New Member

    Oh, will check now!
  8. Stilldabomb

    Stilldabomb New Member

    Haha, works now, thanks a lot, before it was just giving me an error saying "EventListener can not access onMessage with permissions "public"" or something like that, so that's why I removed the public identifier.

    Thanks a ton,
    Stilldabomb!
  9. Matt

    Matt Forum Moderator & Contributor Staff Member Moderator Contributor

    Marked as solved and locked

    Please open a new topic for further questions
Thread Status:
Not open for further replies.

Share This Page