public static boolean hasPermission(
      Resident res, FlagType<Boolean> flagType, int dim, Volume volume) {
    boolean inWild = false;

    for (int townBlockX = volume.getMinX() >> 4;
        townBlockX <= volume.getMaxX() >> 4;
        townBlockX++) {
      for (int townBlockZ = volume.getMinZ() >> 4;
          townBlockZ <= volume.getMaxZ() >> 4;
          townBlockZ++) {
        TownBlock townBlock = MyTownUniverse.instance.blocks.get(dim, townBlockX, townBlockZ);

        if (townBlock == null) {
          inWild = true;
          continue;
        }

        Town town = townBlock.getTown();
        Volume rangeBox = volume.intersect(townBlock.toVolume());

        // If the range volume intersects the TownBlock, check Town/Plot permissions
        if (rangeBox != null) {
          int totalIntersectArea = 0;

          // Check every plot in the current TownBlock and sum all plot areas
          for (Plot plot : townBlock.plotsContainer) {
            Volume plotIntersection = volume.intersect(plot.toVolume());
            if (plotIntersection != null) {
              if (!plot.hasPermission(res, flagType)) {
                return false;
              }
              totalIntersectArea += plotIntersection.getVolumeAmount();
            }
          }

          // If plot area sum is not equal to range area, check town permission
          if (totalIntersectArea != rangeBox.getVolumeAmount()) {
            if (!town.hasPermission(res, flagType)) {
              return false;
            }
          }
        }
      }
    }

    if (inWild) {
      return Wild.instance.hasPermission(res, flagType);
    }

    return true;
  }
Exemple #2
0
  /** Populates the tab completion map. */
  public static void populateCompletionMap() {

    List<String> populator = new ArrayList<String>();
    for (Town town : getUniverse().towns) {
      populator.add(town.getName());
    }

    CommandCompletion.addCompletions("townCompletionAndAll", populator);
    CommandCompletion.addCompletion("townCompletionAndAll", "@a");

    CommandCompletion.addCompletions("townCompletion", populator);

    populator = new ArrayList<String>();
    for (Resident res : getUniverse().residents) {
      populator.add(res.getPlayerName());
    }
    CommandCompletion.addCompletions("residentCompletion", populator);

    populator = new ArrayList<String>();
    for (FlagType flag : FlagType.values()) {
      populator.add(flag.name.toLowerCase());
    }
    CommandCompletion.addCompletions("flagCompletion", populator);

    populator = new ArrayList<String>();
    for (FlagType flag : FlagType.values()) {
      if (flag.isWhitelistable) populator.add(flag.name.toLowerCase());
    }
    CommandCompletion.addCompletions("flagCompletionWhitelist", populator);

    populator = new ArrayList<String>();
    for (Plot plot : MyTownUniverse.instance.plots) {
      populator.add(plot.toString());
    }
    CommandCompletion.addCompletions("plotCompletion", populator);

    populator = new ArrayList<String>();
    for (Rank rank : Rank.defaultRanks) {
      populator.add(rank.getName());
    }
    CommandCompletion.addCompletions("rankCompletion", populator);
  }
Exemple #3
0
  public boolean hasPermission(Resident res, Segment segment, int dim, Volume area) {
    boolean inWild = false;

    for (int townBlockX = area.getMinX() >> 4; townBlockX <= area.getMaxX() >> 4; townBlockX++) {
      for (int townBlockZ = area.getMinZ() >> 4; townBlockZ <= area.getMaxZ() >> 4; townBlockZ++) {
        TownBlock townBlock = getDatasource().getBlock(dim, townBlockX, townBlockZ);

        if (townBlock == null) {
          inWild = true;
        } else {
          Town town = townBlock.getTown();
          Volume rangeBox = townBlock.getAreaLimit(area);
          int totalIntersectArea = 0;

          // Check every plot in the current TownBlock and sum all plot areas
          for (Plot plot : townBlock.getPlots()) {
            int plotIntersectArea = plot.getIntersectingArea(rangeBox);
            if (plotIntersectArea > 0) {
              if (res == null) {
                if (plot.getValue(segment.getFlag()).equals(segment.getDenialValue())) {
                  return false;
                }
              } else {
                if (!plot.hasPermission(res, segment.getFlag(), segment.getDenialValue())) {
                  res.protectionDenial(
                      segment.getFlag().getLocalizedProtectionDenial(),
                      LocalizationProxy.getLocalization()
                          .getLocalization(
                              "mytown.notification.town.owners",
                              town.getMayor() == null
                                  ? "SERVER ADMINS"
                                  : town.getMayor().getPlayerName()));
                  return false;
                }
              }
            }
            totalIntersectArea += plotIntersectArea;
          }

          // If plot area sum is not equal to range area, check town permission
          if (totalIntersectArea != getArea(rangeBox)) {
            if (res == null) {
              if (town.getValue(segment.getFlag()).equals(segment.getDenialValue())) {
                return false;
              }
            } else {
              if (!town.hasPermission(res, segment.getFlag(), segment.getDenialValue())) {
                res.protectionDenial(
                    segment.getFlag().getLocalizedProtectionDenial(),
                    LocalizationProxy.getLocalization()
                        .getLocalization(
                            "mytown.notification.town.owners",
                            town.getMayor() == null
                                ? "SERVER ADMINS"
                                : town.getMayor().getPlayerName()));
                return false;
              }
            }
          }
        }
      }
    }

    if (inWild) {
      if (res == null) {
        if (Wild.instance.getValue(segment.getFlag()).equals(segment.getDenialValue())) {
          return false;
        }
      } else {
        if (!Wild.instance.hasPermission(res, segment.getFlag(), segment.getDenialValue())) {
          res.sendMessage(segment.getFlag().getLocalizedProtectionDenial());
          return false;
        }
      }
    }

    return true;
  }
  public static void check(EntityPlayerMP player) {
    Town town =
        MyTownUtils.getTownAtPosition(
            player.dimension,
            (int) Math.floor(player.posX) >> 4,
            (int) Math.floor(player.posZ) >> 4);
    Resident res = MyTownUniverse.instance.getOrMakeResident(player);
    EntityPos lastTickPos = lastTickPlayerPos.get(player);

    if (res == null) {
      return;
    }

    if (!ProtectionManager.hasPermission(
        res,
        FlagType.ENTER,
        player.dimension,
        (int) Math.floor(player.posX),
        (int) Math.floor(player.posY),
        (int) Math.floor(player.posZ))) {
      if (lastTickPos == null) {
        res.knockbackPlayerToBorder(town);
      } else if (lastTickPos.getX() != player.posX
          || lastTickPos.getY() != player.posY
          || lastTickPos.getZ() != player.posZ
          || lastTickPos.getDim() != player.dimension) {
        PlayerUtils.teleport(
            player,
            lastTickPos.getDim(),
            lastTickPos.getX(),
            lastTickPos.getY(),
            lastTickPos.getZ());
      }
    } else {
      // TODO: Refactor so that it's understandable
      if (lastTickPos != null
          && (((int) Math.floor(lastTickPos.getX())) >> 4 != (int) (Math.floor(player.posX)) >> 4
              || ((int) Math.floor(lastTickPos.getZ())) >> 4
                  != (int) (Math.floor(player.posZ)) >> 4)) {
        if (lastTickPos.getDim() == player.dimension) {
          res.checkLocation(
              ((int) Math.floor(lastTickPos.getX())) >> 4,
              ((int) Math.floor(lastTickPos.getZ())) >> 4,
              ((int) Math.floor(player.posX)) >> 4,
              ((int) (Math.floor(player.posZ))) >> 4,
              player.dimension);
        } else {
          res.checkLocationOnDimensionChanged(
              (int) (Math.floor(player.posX)), (int) (Math.floor(player.posZ)), player.dimension);
        }
      }

      if (lastTickPos != null && town != null) {
        Plot currentPlot =
            town.plotsContainer.get(
                player.dimension,
                (int) Math.floor(player.posX),
                (int) Math.floor(player.posY),
                (int) Math.floor(player.posZ));
        Plot lastTickPlot =
            town.plotsContainer.get(
                lastTickPos.getDim(),
                (int) Math.floor(lastTickPos.getX()),
                (int) Math.floor(lastTickPos.getY()),
                (int) Math.floor(lastTickPos.getZ()));

        if (currentPlot != null && (lastTickPlot == null || currentPlot != lastTickPlot)) {
          res.sendMessage(
              MyTown.instance.LOCAL.getLocalization(
                  "mytown.notification.plot.enter", currentPlot.getName()));
        } else if (currentPlot == null && lastTickPlot != null) {
          res.sendMessage(
              MyTown.instance.LOCAL.getLocalization(
                  "mytown.notification.plot.enter", EnumChatFormatting.RED + "Unassigned"));
        }
      }
      lastTickPlayerPos.put(
          player, new EntityPos(player.posX, player.posY, player.posZ, player.dimension));
    }
  }