[Tutorial] Creating your own custom border limit and border message

Discussion in 'Resources' started by Pezah, Sep 26, 2013.

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

    Pezah

    This tutorial is for all the plugin developers out there that like to keep their server as custom as it can get.

    I'm going to explain to you how you can create your own border limit and message.

    An example;

    Code:java
    1. @EventHandler
    2. public void onMove(PlayerMoveEvent e)
    3. {
    4. Player p = e.getPlayer();
    5. if (e.getTo().getX() > 3000 || e.getTo().getX() < -3000 || e.getTo().getZ() > 3000 || e.getTo().getZ() < -3000)
    6. {
    7. e.setTo(e.getFrom());
    8. p.sendMessage("You wandered out too far!");
    9. }
    10.  
    11. }


    Explained;

    The plugin disallows the player to walk past X: 3000, X: -3000, Z: 3000, Z:-3000

    Broken down;

    Code:java
    1. if (e.getTo().getX() > <intXOfChoice>


    The plugin is checking if the X location is greater than the number of which you will declare to ensure the player cannot walk any further. If the X location is greater than the number, then;

    Code:java
    1. e.setTo(e.getFrom());


    The player is teleported back to where they originally were, and therefore a border is created.

    When the player is teleported back, you can add in a custom message for them by simply sending them a message of your choice like I showed you in the example.

    If you have any questions, let me know and I'll try my best to answer them.
     
  2. Offline

    Mathias Eklund

    So with this, is it from the spawnpoint or coords?
     
  3. Offline

    Pezah

    The event checks the players' X and Y co-ods.
     
  4. Offline

    bloodless2010

    • p.sendMessage(p.sendMessage("You wandered out too far!");
    • Shouldn't that be just
      p.sendMessage("You wandered out too far!");

     
  5. Offline

    Mathias Eklund

    Okey, good to know, will make sure the spawnpoint of my server is at 0 :)
     
  6. Offline

    Pezah

    Yeah, didn't mean to do that, fixed.
     
  7. Offline

    chaseoes

    You'll want to do much more for a true border plugin. See WorldBorder.
    • Boats?
    • Minecarts?
    • Enderpearls?
    • Nether portals?
    • Using a scheduled task instead of the move event is also an option to reduce lag.
     
    netizen539 likes this.
  8. Offline

    Pezah

    Hmmm, they will be some problems... But every problem has a fix, I'll work on these asap.
     
Thread Status:
Not open for further replies.

Share This Page