gt:         if (loc == null || loc.getWorld() == null) {
context: package com.earth2me.essentials;
  
  import com.earth2me.essentials.utils.NumberUtil;
  import com.earth2me.essentials.utils.StringUtil;
  import com.google.common.collect.ImmutableMap;
  import net.ess3.api.IEssentials;
  import net.ess3.api.InvalidWorldException;
  import net.ess3.api.MaxMoneyException;
  import org.bukkit.Location;
  import org.bukkit.configuration.ConfigurationSection;
  import org.bukkit.entity.Player;
  import org.bukkit.inventory.ItemStack;
  
  import java.io.File;
  import java.math.BigDecimal;
  import java.util.*;
  import java.util.Map.Entry;
  import java.util.regex.Pattern;
  
  import static com.earth2me.essentials.I18n.tl;
  
  
  public abstract class UserData extends PlayerExtension implements IConf {
      protected final transient IEssentials ess;
      private final EssentialsUserConf config;
      private final File folder;
  
      protected UserData(Player base, IEssentials ess) {
          super(base);
          this.ess = ess;
          folder = new File(ess.getDataFolder(), "userdata");
          if (!folder.exists()) {
              folder.mkdirs();
          }
  
          String filename;
          try {
              filename = base.getUniqueId().toString();
          } catch (Throwable ex) {
              ess.getLogger().warning("Falling back to old username system for " + base.getName());
              filename = base.getName();
          }
  
          config = new EssentialsUserConf(base.getName(), base.getUniqueId(), new File(folder, filename + ".yml"));
          reloadConfig();
      }
  
      public final void reset() {
          config.forceSave();
          config.getFile().delete();
          if (config.username != null) {
              ess.getUserMap().removeUser(config.username);
          }
      }
  
      public final void cleanup() {
          config.cleanup();
      }
  
      @Override
      public final void reloadConfig() {
          config.load();
          money = _getMoney();
          unlimited = _getUnlimited();
          powertools = _getPowertools();
          homes = _getHomes();
          lastLocation = _getLastLocation();
          lastTeleportTimestamp = _getLastTeleportTimestamp();
          lastHealTimestamp = _getLastHealTimestamp();
          jail = _getJail();
          mails = _getMails();
          teleportEnabled = _getTeleportEnabled();
          godmode = _getGodModeEnabled();
          muted = _getMuted();
          muteTimeout = _getMuteTimeout();
          jailed = _getJailed();
          jailTimeout = _getJailTimeout();
          lastLogin = _getLastLogin();
          lastLogout = _getLastLogout();
          lastLoginAddress = _getLastLoginAddress();
          afk = _getAfk();
          geolocation = _getGeoLocation();
          isSocialSpyEnabled = _isSocialSpyEnabled();
          isNPC = _isNPC();
          arePowerToolsEnabled = _arePowerToolsEnabled();
          kitTimestamps = _getKitTimestamps();
          nickname = _getNickname();
          ignoredPlayers = _getIgnoredPlayers();
          logoutLocation = _getLogoutLocation();
          lastAccountName = _getLastAccountName();
          commandCooldowns = _getCommandCooldowns();
          acceptingPay = _getAcceptingPay();
          confirmPay = _getConfirmPay();
      }
  
      private BigDecimal money;
  
      private BigDecimal _getMoney() {
          BigDecimal result = ess.getSettings().getStartingBalance();
          BigDecimal maxMoney = ess.getSettings().getMaxMoney();
          BigDecimal minMoney = ess.getSettings().getMinMoney();
          
          // NPC banks are not actual player banks, as such they do not have player starting balance.
          if (isNPC()) {
              result = BigDecimal.ZERO;
          }
  
          if (config.hasProperty("money")) {
              result = config.getBigDecimal("money", result);
          }
          if (result.compareTo(maxMoney) > 0) {
              result = maxMoney;
          }
          if (result.compareTo(minMoney) < 0) {
              result = minMoney;
          }
          return result;
      }
  
      public BigDecimal getMoney() {
          return money;
      }
  
      public void setMoney(BigDecimal value, boolean throwError) throws MaxMoneyException {
          BigDecimal maxMoney = ess.getSettings().getMaxMoney();
          BigDecimal minMoney = ess.getSettings().getMinMoney();
          if (value.compareTo(maxMoney) > 0) {
              if (throwError) {
                  throw new MaxMoneyException();
              }
              money = maxMoney;
          } else {
              money = value;
          }
          if (money.compareTo(minMoney) < 0) {
              money = minMoney;
          }
          config.setProperty("money", money);
          stopTransaction();
      }
  
      private Map<String, Object> homes;
  
      private Map<String, Object> _getHomes() {
          if (config.isConfigurationSection("homes")) {
              return config.getConfigurationSection("homes").getValues(false);
          }
          return new HashMap<String, Object>();
      }
  
      private String getHomeName(String search) {
          if (NumberUtil.isInt(search)) {
              try {
                  search = getHomes().get(Integer.parseInt(search) - 1);
              } catch (NumberFormatException e) {
              } catch (IndexOutOfBoundsException e) {
              }
          }
          return search;
      }
  
      public Location getHome(String name) throws Exception {
          String search = getHomeName(name);
          return config.getLocation("homes." + search, this.getBase().getServer());
      }
  
      public Location getHome(final Location world) {
          try {
              if (getHomes().isEmpty()) {
                  return null;
              }
              Location loc;
              for (String home : getHomes()) {
                  loc = config.getLocation("homes." + home, this.getBase().getServer());
                  if (world.getWorld() == loc.getWorld()) {
                      return loc;
                  }
  
              }
              loc = config.getLocation("homes." + getHomes().get(0), this.getBase().getServer());
              return loc;
          } catch (InvalidWorldException ex) {
              return null;
          }
      }
  
      public List<String> getHomes() {
          return new ArrayList<String>(homes.keySet());
      }
  
      public void setHome(String name, Location loc) {
          //Invalid names will corrupt the yaml
          name = StringUtil.safeString(name);
          homes.put(name, loc);
          config.setProperty("homes." + name, loc);
          config.save();
      }
  
      public void delHome(String name) throws Exception {
          String search = getHomeName(name);
          if (!homes.containsKey(search)) {
              search = StringUtil.safeString(search);
          }
          if (homes.containsKey(search)) {
              homes.remove(search);
              config.removeProperty("homes." + search);
              config.save();
          } else {
              throw new Exception(tl("invalidHome", search));
          }
      }
  
      public boolean hasHome() {
          return config.hasProperty("home");
      }
  
      private String nickname;
  
      public String _getNickname() {
          return config.getString("nickname");
      }
  
      public String getNickname() {
          return nickname;
      }
  
      public void setNickname(String nick) {
          nickname = nick;
          config.setProperty("nickname", nick);
          config.save();
      }
  
      private List<Integer> unlimited;
  
      private List<Integer> _getUnlimited() {
          return config.getIntegerList("unlimited");
      }
  
      public List<Integer> getUnlimited() {
          return unlimited;
      }
  
      public boolean hasUnlimited(ItemStack stack) {
          return unlimited.contains(stack.getTypeId());
      }
  
      public void setUnlimited(ItemStack stack, boolean state) {
          if (unlimited.contains(stack.getTypeId())) {
              unlimited.remove(Integer.valueOf(stack.getTypeId()));
          }
          if (state) {
              unlimited.add(stack.getTypeId());
          }
          config.setProperty("unlimited", unlimited);
          config.save();
      }
  
      private Map<String, Object> powertools;
  
      private Map<String, Object> _getPowertools() {
          if (config.isConfigurationSection("powertools")) {
              return config.getConfigurationSection("powertools").getValues(false);
          }
          return new HashMap<String, Object>();
      }
  
      public void clearAllPowertools() {
          powertools.clear();
          config.setProperty("powertools", powertools);
          config.save();
      }
  
      @SuppressWarnings("unchecked")
      public List<String> getPowertool(ItemStack stack) {
          return (List<String>) powertools.get("" + stack.getTypeId());
      }
  
      @SuppressWarnings("unchecked")
      public List<String> getPowertool(int id) {
          return (List<String>) powertools.get("" + id);
      }
  
      public void setPowertool(ItemStack stack, List<String> commandList) {
          if (commandList == null || commandList.isEmpty()) {
              powertools.remove("" + stack.getTypeId());
          } else {
              powertools.put("" + stack.getTypeId(), commandList);
          }
          config.setProperty("powertools", powertools);
          config.save();
      }
  
      public boolean hasPowerTools() {
          return !powertools.isEmpty();
      }
  
      private Location lastLocation;
  
      private Location _getLastLocation() {
          try {
              return config.getLocation("lastlocation", this.getBase().getServer());
          } catch (InvalidWorldException e) {
              return null;
          }
      }
  
      public Location getLastLocation() {
          return lastLocation;
      }
  
      public void setLastLocation(Location loc) {
          if (loc == null || loc.getWorld() == null) {
              return;
          }
          lastLocation = loc;
          config.setProperty("lastlocation", loc);
          config.save();
      }
  
      private Location logoutLocation;
  
      private Location _getLogoutLocation() {
          try {
              return config.getLocation("logoutlocation", this.getBase().getServer());
          } catch (InvalidWorldException e) {
              return null;
          }
      }
  
      public Location getLogoutLocation() {
          return logoutLocation;
      }
  
      public void setLogoutLocation(Location loc) {
  