Checking if a player is in the same world as a preset location

Discussion in 'Plugin Development' started by Doamax, Jan 3, 2014.

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

    Doamax

    This is supposed to check if the player is in the same world as a preset location (config) then calculate the distance. For some reason, this is passing through when the worlds are not equal and it tries to calculate the distance, which returns null obviously.
    Code:java
    1. //check if it is in the same world
    2. if(playerLoc.getWorld().getName().equalsIgnoreCase(main.getConfig().
    3. getString("cannons." + name + ".location.world"))){
    4. //if it isn't within 10 blocks of the player
    5. if(startHash.get(name).distance(pLoc) > 10){
     
  2. Offline

    lordbobby104

    Doamax try removing the equalsIgnoreCase and just putting equals
     
  3. Offline

    Doamax

    It didn't work with == before, so I changed it to equalsIgnoreCase().
     
  4. Offline

    lordbobby104

    Doamax no I'm mean use the .equals method but I guess it wouldn't really matter
     
  5. Offline

    JRL1004

    Doamax You can use Bukkit.getWorld(String) to get an actual world (check if it's null as the method returns null if the world does not exist) then just compare the worlds
     
Thread Status:
Not open for further replies.

Share This Page