Execute message when standing at a location

Discussion in 'Plugin Development' started by Teddinator, Oct 24, 2013.

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

    Teddinator

    What the title said. I need it to execute something when the player is standing at a location. Here is my code:

    Code:
    @EventHandler
        public static boolean isAtSpawn(Player player) {
            double px = player.getLocation().getX();
            double py = player.getLocation().getY();
            double pz = player.getLocation().getZ();
         
            if((px < -223 && px > -221) && (py < 77 && py > 77) && (pz < 221 && pz > 221)) {
                player.sendMessage("Hello");   
                return true;
                    }
            else {
            }
            return true;
            }
     
  2. Offline

    5pHiNxX

  3. Offline

    Teddinator

    If possible, could someone post an example, I am having trouble getting it setup. Thanks again.
     
  4. Offline

    MineDoubleSpace

    Teddinator Use PlayerMoveEvent and check if players location == to your location.
     
  5. Offline

    5pHiNxX

    @Teddinator:

    Code:java
    1. @EventHandler
    2. public static void isAtSpawn(PlayerMoveEvent event) {
    3. Player player = event.getPlayer();
    4. double px = player.getLocation().getX();
    5. double py = player.getLocation().getY();
    6. double pz = player.getLocation().getZ();
    7.  
    8. if((px < -223 && px > -221) && (py < 77 && py > 77) && (pz < 221 && pz > 221)) {
    9. player.sendMessage("Hello");
    10. return true;
    11. }
    12. return true;
    13. }


    @Teddinator:
    to get the spawn of a world use:
    Code:java
    1. Location spawn = player.getWorld().getSpawnLocation();


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    ZeusAllMighty11

    5pHiNxX

    Event methods are void only.
     
  7. Offline

    5pHiNxX

Thread Status:
Not open for further replies.

Share This Page