Player Locations

Discussion in 'Plugin Development' started by dlange, Feb 23, 2015.

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

    dlange

    I'm trying to detect where a player is and if they are at that location to perform a method.
    This is my code:
    Code:
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent e) {
    
            Player player = e.getPlayer();
            Location loc1 = new Location(Bukkit.getServer().getWorld("hub"), 0, 5, 0);
    
            if (player.getLocation().getX() == loc1.getX && player.getLocation().getY() == loc1.getY && player.getLocation().getZ() == loc1.getZ) {
                       //Method
            }
        }
    Anyone know what i am doing wrong here?
     
  2. Offline

    kreashenz

    Try use
    if(player.getLocation().getX() == <int x> && player.getLocation().getY() == <int y> ...)
    instead of making a new location and getting the x,y,z.
     
  3. Offline

    dlange

    Still doesn't work... Just nothing happens, i even try making it print "Test" when they get to the location before the method, but it still doesn't come up :/
    Am i doing the wrong method for such a thing?
     
  4. Offline

    kreashenz

    Are you registering your event(s) in the onEnable method?
     
  5. Offline

    dlange

    Oh ffs lol im retarded sorry xD i made a new class for this listener and forgot ;-;

    EDIT: Just tested it... Doesn't work still, i tested it by sending a message when the event is called and that works, just the location part doesn't.
     
    Last edited: Feb 23, 2015
  6. Offline

    kreashenz

    Haha :) Still, using the
    would be a lot better than how you are checking it now.
     
  7. Offline

    dlange

    Ah ok, so i did that and it works but only when i am at 0.0 5.0 0.0, can i make it anywhere on 0, 5, 0?

    EDIT: Ahh don't worry, i did this:
    Code:
            if (player.getLocation().getX() >= X1 && player.getLocation().getX() <= X2 && player.getLocation().getZ() >= Z1 && player.getLocation().getZ() <= Z2) {
    
    And it works :D
    Thanks !
     
    Last edited: Feb 24, 2015
Thread Status:
Not open for further replies.

Share This Page