Beispiel #1
0
  /**
   * getCachePermission
   *
   * <p>returns player cached permission for BUILD, DESTROY, SWITCH or ITEM_USE
   *
   * @param player
   * @param location
   * @param action
   * @return true if the player has permission.
   */
  public boolean getCachePermission(Player player, Location location, ActionType action) {

    WorldCoord worldCoord;

    try {
      worldCoord =
          new WorldCoord(
              TownyUniverse.getDataSource().getWorld(player.getWorld().getName()),
              Coord.parseCoord(location));
      PlayerCache cache = TownyUniverse.getPlugin().getCache(player);
      cache.updateCoord(worldCoord);

      TownyMessaging.sendDebugMsg(
          "Cache permissions for " + action.toString() + " : " + cache.getCachePermission(action));
      return cache.getCachePermission(
          action); // || plugin.isTownyAdmin(player); // Throws NullPointerException if the cache is
                   // empty

    } catch (NotRegisteredException e) {
      // World not known
      e.printStackTrace();
    } catch (NullPointerException e) {
      // New or old cache permission was null, update it

      try {
        worldCoord =
            new WorldCoord(
                TownyUniverse.getDataSource().getWorld(player.getWorld().getName()),
                Coord.parseCoord(location));

        TownBlockStatus status =
            cacheStatus(player, worldCoord, getStatusCache(player, worldCoord));
        // plugin.cacheBuild(player, worldCoord, plugin.getPermission(player, status, worldCoord,
        // action));
        triggerCacheCreate(player, location, worldCoord, status, action);

        PlayerCache cache = TownyUniverse.getPlugin().getCache(player);
        cache.updateCoord(worldCoord);

        TownyMessaging.sendDebugMsg(
            "New Cache permissions for "
                + action.toString()
                + " : "
                + cache.getCachePermission(action));
        return cache.getCachePermission(action); // || plugin.isTownyAdmin(player);

      } catch (NotRegisteredException e1) {
        // Will never get here.
      }
    }
    return false;
  }