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.

Tutorial: Redirect (Teleport) players cross-server

Discussion in 'Tutorials' started by hawkfalcon, Jun 1, 2013.

  1. hawkfalcon

    hawkfalcon New Member

    Hello everyone! Lilypad is a very amazing and versatile server software for both owners and devs alike. However, I feel that it is severely lacking in documentation. I am going to be making some tutorials about thing that can be done with Lilypad and how to accomplish them!
    This tutorial will show you how to redirect (teleport) a player to another server.

    To begin, you must establish a connection with LilyPad.
    Code (java):
        public Connect getBukkitConnect() {
            return (Connect) plugin.getServer().getServicesManager().getRegistration(Connect.class).getProvider();
        }
     
    Next, we can make a method specifying the player which we wish to send and the username of the serve where we with to send them. This method calls a redirect request, asking lilypad to transfer a player. If the server is down or it fails, it will say that if cannot connect.
    Code (java):

    public void redirectRequest(String server, final Player player) {
            try {
              //create connection
                Connect c = getBukkitConnect();
                //new RedirectRequest to transfer the player
                c.request(new RedirectRequest(server, player.getName())).registerListener(new FutureResultListener<RedirectResult>() {
                  //listen for a successful transfer
                    public void onResult(RedirectResult redirectResult) {
                        if (redirectResult.getStatusCode() == StatusCode.SUCCESS) {
                            return;
                        }
                        player.sendMessage("Could not connect");
                    }
                });
     
            } catch (Exception exception) {
                        player.sendMessage("Could not connect");
            }
        }
    It is as easy as that! Next time I will show you how you can use messagerequests to talk between servers.
    Have fun!
    hawkfalcon
    • Like Like x 2
    • Informative Informative x 1
  2. inventorman101

    inventorman101 New Member

    Hey hawkfalcon :)
    I was wondering how could I make it so when a player right clicks on a sign then it will teleport them to the corresponding server?
  3. hawkfalcon

    hawkfalcon New Member

    Listen to the PlayerInteractEvent, check if its a sign, check the sign text, redirect the player.
  4. inventorman101

    inventorman101 New Member

    Thanks, hawkfalcon how do I know what server the sign is targeting?

    p.s. I am new to LilyPad :p
  5. boboman13

    boboman13 Member Contributor

    inventorman101 that part would be plugin sided, you could either check and store the sign Location in a config, or you could have, say, line[1] be "Survival", and it would redirect you to the Survival server.
    • Friendly Friendly x 1

Share This Page