Пример #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;
  }
Пример #2
0
  public void cacheItemUse(Player player, WorldCoord worldCoord, boolean itemUseRight) {
    PlayerCache cache = TownyUniverse.getPlugin().getCache(player);
    cache.updateCoord(worldCoord);
    cache.setItemUsePermission(itemUseRight);

    TownyMessaging.sendDebugMsg(
        player.getName() + " (" + worldCoord.toString() + ") Cached Item Use: " + itemUseRight);
  }
Пример #3
0
  public void cacheSwitch(Player player, WorldCoord worldCoord, boolean switchRight) {
    PlayerCache cache = TownyUniverse.getPlugin().getCache(player);
    cache.updateCoord(worldCoord);
    cache.setSwitchPermission(switchRight);

    TownyMessaging.sendDebugMsg(
        player.getName() + " (" + worldCoord.toString() + ") Cached Switch: " + switchRight);
  }
Пример #4
0
  public void cacheDestroy(Player player, WorldCoord worldCoord, boolean destroyRight) {
    PlayerCache cache = TownyUniverse.getPlugin().getCache(player);
    cache.updateCoord(worldCoord);
    cache.setDestroyPermission(destroyRight);

    TownyMessaging.sendDebugMsg(
        player.getName() + " (" + worldCoord.toString() + ") Cached Destroy: " + destroyRight);
  }
Пример #5
0
  public void cacheBuild(Player player, WorldCoord worldCoord, boolean buildRight) {
    PlayerCache cache = TownyUniverse.getPlugin().getCache(player);
    cache.updateCoord(worldCoord);
    cache.setBuildPermission(buildRight);

    TownyMessaging.sendDebugMsg(
        player.getName() + " (" + worldCoord.toString() + ") Cached Build: " + buildRight);
  }
Пример #6
0
  public TownBlockStatus cacheStatus(
      Player player, WorldCoord worldCoord, TownBlockStatus townBlockStatus) {
    PlayerCache cache = TownyUniverse.getPlugin().getCache(player);
    cache.updateCoord(worldCoord);
    cache.setStatus(townBlockStatus);

    TownyMessaging.sendDebugMsg(
        player.getName() + " (" + worldCoord.toString() + ") Cached Status: " + townBlockStatus);
    return townBlockStatus;
  }
Пример #7
0
  /**
   * getTownBlock
   *
   * <p>returns TownBlock this location lies within if no block is registered it returns null
   *
   * @param loc
   * @return TownBlock at this location, or null for none.
   */
  public TownBlock getTownBlock(Location loc) {

    TownyMessaging.sendDebugMsg("Fetching TownBlock");

    try {
      WorldCoord worldCoord =
          new WorldCoord(getDataSource().getWorld(loc.getWorld().getName()), Coord.parseCoord(loc));
      return worldCoord.getTownBlock();
    } catch (NotRegisteredException e) {
      // No data so return null
      return null;
    }
  }