Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
  public void sendClientUpdate(
      Volume updateVolume, BlockPos center, EntityPlayerMP player, ForgeDirection face) {
    World world = DimensionManager.getWorld(center.getDim());
    int x, y, z;

    if (face != null) updateVolume = translateVolume(updateVolume, face);

    for (int i = updateVolume.getMinX(); i <= updateVolume.getMaxX(); i++) {
      for (int j = updateVolume.getMinY(); j <= updateVolume.getMaxY(); j++) {
        for (int k = updateVolume.getMinZ(); k <= updateVolume.getMaxZ(); k++) {
          x = center.getX() + i;
          y = center.getY() + j;
          z = center.getZ() + k;

          S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world);
          packet.field_148884_e = world.getBlockMetadata(x, y, z);
          FMLCommonHandler.instance()
              .getMinecraftServerInstance()
              .getConfigurationManager()
              .sendPacketToAllPlayers(packet);
        }
      }
    }
  }
Exemplo n.º 3
0
 public int getArea(Volume rangeBox) {
   return ((rangeBox.getMaxX() - rangeBox.getMinX()) + 1)
       * ((rangeBox.getMaxY() - rangeBox.getMinY()) + 1)
       * ((rangeBox.getMaxZ() - rangeBox.getMinZ()) + 1);
 }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
  public Volume translateVolume(Volume volume, ForgeDirection direction) {
    if (direction == ForgeDirection.UNKNOWN) return volume;

    switch (direction) {
      case DOWN:
        volume =
            new Volume(
                volume.getMinX(),
                -volume.getMaxZ(),
                volume.getMinY(),
                volume.getMaxX(),
                volume.getMinZ(),
                volume.getMaxY());
        break;
      case UP:
        volume =
            new Volume(
                volume.getMinX(),
                volume.getMinZ(),
                volume.getMinY(),
                volume.getMaxX(),
                volume.getMaxZ(),
                volume.getMaxY());
        break;
      case NORTH:
        volume =
            new Volume(
                volume.getMinX(),
                volume.getMinY(),
                -volume.getMaxZ(),
                volume.getMaxX(),
                volume.getMaxY(),
                volume.getMinZ());
        break;
      case WEST:
        volume =
            new Volume(
                -volume.getMaxZ(),
                volume.getMinY(),
                volume.getMinX(),
                volume.getMinZ(),
                volume.getMaxY(),
                volume.getMaxX());
        break;
      case EAST:
        volume =
            new Volume(
                volume.getMinZ(),
                volume.getMinY(),
                volume.getMinX(),
                volume.getMaxZ(),
                volume.getMaxY(),
                volume.getMaxX());
        break;
      case SOUTH:
        // The orientation on South is already the correct one, no translation needed.
        break;
    }
    return volume;
  }